the code word you are looking for is "VAR"
- to pass data to a procedure which doesn't have to alter that variable:
type
TMyArray = array of string;
procedure Test1(arr: TMyArray);
begin
ShowMessage(Format('Array elements: %d', [High(arr)]));
end;
to pass data to a procedure which has to alter (or fill in the variable):
type
TMyArray = array of string;
procedure Test2(var arr: TMyArray);
var I: Integer;
begin
SetLength(arr, 10);
for I := Low(arr) to High(arr) do
arr[I] := IntToStr(I);
end;
you can also alter the number of parameters
type
TMyArray = array of string;
procedure Test3(var arr1, arr2: TMyArray);
var I: Integer;
begin
SetLength(arr1, 10);
for I := Low(arr1) to High(arr1) do
arr1[I] := IntToStr(I);
SetLength(arr2, 20);
for I := Low(arr2) to High(arr2) do
arr2[I] := IntToStr(I);
end;
or write Test3 like this:
type
TMyArray = array of string;
procedure Test3(var arr1, arr2: TMyArray);
var I: Integer;
begin
Test2(arr1);
SetLength(arr2, 20);
for I := Low(arr2) to High(arr2) do
arr2[I] := IntToStr(I);
end;