[fpc-pascal] Varriable number of parameters

Michalis Kamburelis michalis at camelot.homedns.org
Thu May 12 13:23:44 CEST 2005


Anandu R Suri wrote:
> Hi, how can I create procedure with undefined number of parrameters. Writeln
> is example of what I am looking for for example procedure add(a,b,c,.... var
> result)
> Pianoman
> 
> Declare a Function or a procedure as
>     MyProc(P1: String; Args: Array of Const);
> 
> And as Michael Van Canneyt said, you can use as many parameters. But dont
> forget to compile it with -S2 option.
> 
> Like C, you must provide some method to distinguish between different data
> types within the first parameter itself, and access the rest using:
>     Args[ParameterNumber].vChar for Char
>     Args[ParameterNumber].vString for string and
>     Args[ParameterNumber].vInteger for integer data types.
> 

Actually, quite the contrary: Unlike C "..." construct, you *don't* have 
to encode in 1st parameter exact types of the variable parameters. Args 
is just an array of TVarRec records:
- you can gen their Length by High(Args),
- and you can check their types at runtime by looking at 
Args[ParameterNumber].vType

Michalis




More information about the fpc-pascal mailing list