[fpc-pascal] Re: Runtime error 217 on array of Variant
Xiangrong Fang
xrfang at gmail.com
Thu Sep 5 06:20:36 CEST 2013
I found the problem myself. You have to add "uses Variants" to eliminate
the problem. So now my questions are:
1) why the Variants unit is required? What does it do?
2) is there any performance penalty using Variant than TVarRec?
Thanks!
2013/9/5 Xiangrong Fang <xrfang at gmail.com>
> Hi there,
>
> I would like to use TVarRec as Variants, after some googling I found this:
>
>
> http://stackoverflow.com/questions/3733640/how-to-convert-between-tvarrec-and-variant
>
> However, it generated Runtime error 217. My original code (runs OK) is:
>
> 1 program test;
> 2 {$mode objfpc}{$H+}
> 3 procedure vart(par: array of const);
> 4 var
> 5 i: Integer;
> 6 begin
> 7 i := par[0].VInteger;
> 8 WriteLn('first param=', i);
> 9 end;
> 10 begin
> 11 vart([1, 2, 3]);
> 12 end.
>
> Modified code (runtime error 217) is:
>
> 1 program test;
> 2 {$mode objfpc}{$H+}
> 3 procedure vart(par: array of Variant);
> 4 var
> 5 i: Integer;
> 6 begin
> 7 i := par[0];
> 8 WriteLn('first param=', i);
> 9 end;
> 10 begin
> 11 vart([1, 2, 3]);
> 12 end.
>
> Any ideas? Thanks!
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20130905/8ac75ba1/attachment.html>
More information about the fpc-pascal
mailing list