Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

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

Posted on 2010-08-25
Medium Priority
1,835 Views
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
Question by:HenryM2
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2

LVL 13

Expert Comment

ID: 33520114
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

LVL 13

Accepted Solution

aflarin earned 2000 total points
ID: 33520117
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 Closing Comment

ID: 33520225
Thanks
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
###### Suggested Courses
Course of the Month5 days, 4 hours left to enroll