Solved

# dynamic array

Posted on 2002-04-27
328 Views
How can I create a dynamic array (from variant ?) of a user defined record ?

Andrew
0
Question by:andrewyu
[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

LVL 27

Expert Comment

ID: 6972947
type
TRecord = record
....
end;
TRecArray : Array of TRecord;

var
ARecArray : TRecArray;

...

0

Author Comment

ID: 6972949
How can I resize or define dimension of ARecArray ?

Andrew
0

LVL 22

Expert Comment

ID: 6972991
SetLength(MyArr,100);
0

Author Comment

ID: 6973396
Therefore, I can access the array from MyArr[0] to MyArr[99].

However, how can I create a multi-dimension array with SetLength ?

Andrew
0

LVL 25

Accepted Solution

Tomas Helgi Johannsson earned 100 total points
ID: 6973488
Hi!

Add the following to the type declartion :
TMRecArray = Array of TRecArray;

The variable should be
ARecArray : TMRecArray;

Then to initialize the multidimenisionalarray
like this

procedure TForm1.FormCreate(Sender: TObject);
var
i,j,max : Integer;
begin
max := 100
SetLength(ARecArray,max);
for j := 0 to max-1 do
begin
SetLength(ARecArray[j],max);
end;
for i := 0 to max-1 do
for j := 0 to max-1 do
ARecArray[i][j].<record field name> := <what ever>;
end;

This example is a 100x100 matrix. If you want to add a dimmension to your array then you just add in the type declaration <a new name of array type> : <the last name of array type> and so on. And the variable to the new name of the array type.
Then in the initalization you should add some code like this

procedure TForm1.FormCreate(Sender: TObject);
var
i,j...,z,max : Integer;
begin
max := 100
SetLength(ARecArray,max);
for j := 0 to max-1 do
begin
SetLength(ARecArray[j],max);
for k := 0 to max-1 do
begin
SetLength(ARecArray[j][k],max);
for ...
begin
SetLength(ARecArray[j][k]....,max);
end
end;
end;
end;

The for loops for each additional dimmension should be like the for k:= - loop.

Just remember to free the memory :)

Regards,
Tomas Helgi
0

LVL 1

Expert Comment

ID: 6973847
Have you been helped here, or is more needed?
Moondancer - EE Moderator
0

Author Comment

ID: 6974397
Thank you very much !

Andrew
0

LVL 1

Expert Comment

ID: 6974821
Thank you, Andrew, for returning and finalizing this.
Moondancer - EE Moderator
0

## Featured Post

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
###### Suggested Courses
Course of the Month6 days, 8 hours left to enroll