Solved

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

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Strange behavior when a form is closed 6 44
sumDigits  challenge 7 62
countX 22 71
QRReport  TQrmemo vertical stretching 1 37
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 purpose of this article is to demonstrate how we can use conditional statements using Python.
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 will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

744 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

15 Experts available now in Live!

Get 1:1 Help Now