Question : Delphi Loading Data Into Two Dynamic Arras From a Single Procedure

I have a called lest say, Procedure1, declaring the following two dtynamic arrays:
Var SourceArray, DestArray : array of String;

From Procedure1 I want to call Procedure2 or Function2 where I want to load data into SourceArray or DestArray, by passing the name of the Array to Procedure 2, hence controlling through the passing of the Array's name, into which Array Procedure 2 is to load the data.  How is this done?

Answer : Delphi Loading Data Into Two Dynamic Arras From a Single Procedure

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;



Random Solutions  
 
programming4us programming4us