Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Building Array of Const on the fly

729 views
Skip to first unread message

dave....@gmail.com

unread,
Jul 29, 2008, 8:18:05 PM7/29/08
to
Why can't I do something like the following?

procedure test(numArgs:integer; MyFormattingString:string);
var
v:variant;
i:integer;
begin
v:=VarArrayCreate([0,numArgs],varVariant);
for i:=1 to numArgs do
v[i-1]:=myDataSet.FieldByName(inttostr(i)).asstring;
memo1.lines.add(Format(MyFormattingString,[v]);
.........

I want to build the arguments I give to Format on the fly. Is there
any way to do this?

Jaelani

unread,
Aug 9, 2008, 10:40:24 AM8/9/08
to
You have to declare "v" as "array of TVarRec" instead of "variant".
See below.

var
v:array of tvarrec;
i:integer;
begin
setlength(v, numArgs);


for i:=1 to numArgs do

begin
v[i-1].vtype:=vtpchar;

v[i-1].vtpchar:=strnew(pchar(myDataSet.FieldByName(inttostr(i)).asstring));
end;
memo1.lines.add(Format(MyFormattingString,v);
for i:=1 to numArgs do strdispose(v[i-1].vtpchar);
.........

Delphi can build this array on the fly but only for function
parameters such as the one used by the Format function. For manual
creation, it has to be done like above.

0 new messages