Solved

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

Posted on 2010-08-25
3
1,661 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 AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mapBully challenge 6 133
URL for downloading Google Chrome for Win XP 2 154
Message not shown 5 50
Firemonkey allowing RTL on android 6 31
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
The goal of this video is to provide viewers with basic examples to understand and use conditional 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.

770 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