Return to Snippet

Revision: 69712
at August 21, 2015 05:30 by xyzeugene


Initial Code
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'

Initial URL


Initial Description
Variable # of parameters, TVarRec


Thanks, here's an example of a function accepting 
a variable # of parameters for anyone interested:

Initial Title
Delphi/Lazarus: function accepting  a variable # of parameters

Initial Tags


Initial Language
Delphi