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 <xrf...@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! > > >
_______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal