• Status: Solved
• Priority: Medium
• Security: Public
• Views: 2138

# Delphi Is there a simple way to Concat two Dynamic Arrays in to one Array?

I have two Arrays
AVar Array1, Array2 : Array Of String;

Is there a way to concatinate the contents of both into a single array?
0
HenryM2
• 2
1 Solution

Commented:
type
TStringArray = array of string;

function ConcatArrays( A1, A2: array of string): TStringArray;
var
i: Integer;
begin
SetLength( Result, High(A1) + High(A2) + 2 );
for i := 0 to High(A1) do
Result[i]:= A1[i];

for i := 0 to High(A2) do
Result[High(A1)+1+i]:= A2[i];
end;
0

Commented:
using and testing:

procedure TForm1.Button1Click(Sender: TObject);
var
StrArray1, StrArray2, ResArray: TStringArray;
begin
SetLength( StrArray1, 3);
StrArray1[0]:= 'Str 13';
StrArray1[1]:= 'Str 12';
StrArray1[2]:= 'Str 11';

SetLength( StrArray2, 3);
StrArray2[0]:= 'Str 23';
StrArray2[1]:= 'Str 22';
StrArray2[2]:= 'Str 21';

ResArray:= ConcatArrays( StrArray1, StrArray2 );

ShowMessage( ResArray[3] );
end;
0

Author Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.