On 04/10/2020 20:58, James Richters via fpc-pascal wrote:
I’m wondering if there is a way to pass an array of values to a
Procedure without defining an array variable….
For example, if I have a Procedure:
Procedure DoSomething(X :Byte);
Then I can call it with a specific a variable like this:
Var
ThingA :Byte;
…
DoSomething(ThingA);
And I can also call it without a variable but instead just hard code a
specific value like this:
DoSomething($1A);
So if I have a procedure like this:
Procedure DoSomethingElse(Y :Array of Byte);
I can call it like this:
Var
ThingB :Array Of Byte;
SetLength(ThingB,3);
ThingB[0] :=$12;
ThingB[1] :=$1A;
ThingB[2] :=$2B;
DoSomethingElse(ThingB);
But can I also just call it with specific values somehow?
DoSomethingElse([$12,$1A,$2B]);for example… of course this doesn’t
work, but is there a syntax that would work?
There is array of const syntax.
== code==
program project1;
{$mode objfpc}
procedure ShowArray(anArray: array of const);
var
i: Integer;
begin
for i := Low(anArray) to High(anArray) do
case anArray[i].VType of
vtInteger: WriteLn(anArray[i].VInteger,' ');
vtChar: WriteLn(anArray[i].VChar,' ');
end;
end;
begin
ShowArray([99, -1, 'p', 'G']);
ReadLn;
end.
== code end==
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal