<div dir="ltr"><div><div>I found the problem myself. You have to add "uses Variants" to eliminate the problem. So now my questions are:<br><br></div>1) why the Variants unit is required? What does it do?<br><br>
</div>2) is there any performance penalty using Variant than TVarRec?<br><br>Thanks!<br><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/9/5 Xiangrong Fang <span dir="ltr"><<a href="mailto:xrfang@gmail.com" target="_blank">xrfang@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Hi there,<br><br>I would like to use TVarRec as Variants, after some googling I found this:<br><br>
<a href="http://stackoverflow.com/questions/3733640/how-to-convert-between-tvarrec-and-variant" target="_blank">http://stackoverflow.com/questions/3733640/how-to-convert-between-tvarrec-and-variant</a><br>
<br></div>However, it generated Runtime error 217. My original code (runs OK) is:<br><div><div><br><span style="font-family:courier new,monospace"> 1 program test;<br> 2 {$mode objfpc}{$H+}<br> 3 procedure vart(par: array of const);<br>
4 var<br> 5 i: Integer;<br> 6 begin<br> 7 i := par[0].VInteger;<br> 8 WriteLn('first param=', i);<br> 9 end;<br> 10 begin<br> 11 vart([1, 2, 3]);<br> 12 end.</span><br><br></div><div>Modified code (runtime error 217) is:<br>
<br><span style="font-family:courier new,monospace"> 1 program test;<br> 2 {$mode objfpc}{$H+}<br> 3 procedure vart(par: array of Variant);<br> 4 var<br> 5 i: Integer;<br> 6 begin<br> 7 i := par[0];<br> 8 WriteLn('first param=', i);<br>
9 end;<br> 10 begin<br> 11 vart([1, 2, 3]);<br> 12 end.</span><br><br></div><div>Any ideas? Thanks!<br></div><div><br></div><div><br></div></div></div>
</blockquote></div><br></div>