Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2013-09

Runtime error 217 on array of Variant

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Xiangrong Fang

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!

Xiangrong Fang
to Xiangrong Fang

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

Show quoted text 41 lines
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!
Sven Barth
to Xiangrong Fang
"Xiangrong Fang" wrote
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?

The Variants unit implements the conversion operators. Normally the unit is automatically included if you use variants, but in case of parameters and function results this does not work currently... (already reported)

2) is there any performance penalty using Variant than TVarRec?

Variants are said to be slower than TVarRec, but they also are more flexible on the other hand.

Regards,
Sven