/ Published in: Delphi
Variable # of parameters, TVarRec
Thanks, here's an example of a function accepting
a variable # of parameters for anyone interested:
Thanks, here's an example of a function accepting
a variable # of parameters for anyone interested:
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function Add(const Args:array of const):string; var I,N:integer; ArgsI:TVarRec; S:string; begin N:=High(Args); S:=''; for I:=0 to N do begin ArgsI:=Args[I]; case ArgsI.VType of vtInteger: S:=S+IntToStr(ArgsI.VInteger); vtBoolean: if(ArgsI.VBoolean)then S:=S+IntToStr(1) else S:=S+IntToStr(0); vtChar: S:=S+ArgsI.VChar; vtString: S:=S+ArgsI.VString^; end; end; Add:=S; end; procedure Test; var C:string; begin C:=Add([false,true,2,'-','Three']); end; C='012-Three'