Solved

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

Posted on 2010-08-25
3
1,632 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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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 …
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 goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

919 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now