Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2010-08-25
3
Medium Priority
?
1,876 Views
Last Modified: 2013-11-23
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
Comment
Question by:HenryM2
  • 2
3 Comments
 
LVL 13

Expert Comment

by:aflarin
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

by:
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

by:HenryM2
ID: 33520225
Thanks
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question