I am trying to write a few very dynamic procedures and functions and wonder about transferring parameters to a procedure as an Array.
This is actually easy enough done.... just that I would like to pass something like

VAR 
  a,b,c             : INTEGER;
  Name, Text1,Text2 : STRING;
  todaysDate        : TDate;

PROCEDURE HandleValues(Const Values:ARRAY OF ???)
  BEGIN
    // Code to handle fetching the values.
  END;


BEGIN
  HandleValues([a,b,c,Name,Text1,TodaysDate]);
  HandleValues([Name,Text1,Text2,a,c]);
END.

The whole point is that I do not know in which order the parameters occur in the array.
I do not know what type comes where.
If it only was a few possibilities, I would use OVERLOAD, but since my HandleValues procedure some times only get one parameter and other times maybe 30-50 parameters, Overload simply can not be used because the possible variations would be similar to those in lotto.

In my procedure HandleValues I need to be able to distinguish which type the parameter is as well. This so that it can be dealt with accordingly.

Any ideas of how to solve this?
Many thanks in advance.

What language are you using ? Pascal ? You can create your own variant record and pass an array of that. Not sure if array of const will work.

Hmmm. What language I use :-)
I would like to say that it is Turbo Pascal. I use Delphi 9 though.
I don't really get the difference between Turbo Pascal and Delphi.
I think the main difference is all the premade stuff with forms and components written for windows.
I just program Turbo Pascal with Delphi 9 and its components and forms :-)

I suppose I can use a variant record as an array of parameters. Not sure how to automatically find the variable I am dealing with afterwards though.
The whole point is that I want to pass some parameters with only 1 line of code.
If needing to add a lot of different code in order to preset an array before then passing the array as a parameter, then the whole point of making procedure is gone.

Maybe you have an example of how to use a variant record for such a task ?

To pass parameters as a variant record works to a certain degree.
The procedure VarType(Variant) returns Double on TDate and TTime though.
In a way, it does make sense because TDate and TTime is actually a Double.
It is just strange that the variant holds VarDate as an identifier, but can not identify it :-)

Similarily I have problems when passing a STRING as a parameter. VarType(Name) does not recognize that Name is a variable of type STRING. SHORTSTRING however is no problem.

There seem to be a few caveeats with parameters as variant because it does not necessarily recognize the actual type given in the array of parameters.
...
I moved on to trying out ARRAY OF CONST as a parameter.
This seem to work better.
Strings are recognized. Double is recognized as Extended. but then again. I think this is where I will continue my development. I need strings to be recognized, but a double to be extended, that is just a minor triviality that can be solved easily in my routines as I know which types to be expected in the array of parameters.

Many thanks for pointing me in the somewhat right direction :-)

commented: Thanks for the update. +14
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.