Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic Array Creation? 1

Status
Not open for further replies.

SpeedDemon

Programmer
Jan 1, 2001
70
GB
Hi all, is it possible at all to create a new array mid execution in runtime?

eg..

test : array[1..X] of integer; or something similar?

Cheers all.
 
You can set the length of an array dynamically if you don't initially specify the size.
Code:
var
   test: array of Integer;
...
SetLength(test, X);
This array will be indexed from 0.
 
Hi, me again, is there any way todo this with a multi-dimentional array?

Cheers
 
Code:
test: array of array of Integer;
...
SetLength(test, X);
SetLength(test[0], Y);
etc.
 
Hi, im trying the SetLength(test[0], Y); method in a simply loop...

for i:=0 to 100 do
begin
SetLength(test, 2);
end;

however when compiling i get:
[Error] fr_reportfin.pas(202): Missing operator or semicolon
 
Hi again, once I;ve done with the array, because it was genereated dynamically, do I need to close it down to free up memory?

Cheers
 
Cheers mike, all working perfectly...

tek-tips need to start giving out prozes to great geezers like yourself :)

Cheers again
 
if I Declared variable on Delphi 3 as follow :

Var
a : array of integer;

Why I get error :

Error: C:\Program Files\Borland\Delphi 3\Unit1.pas(24): '[' expected but 'OF' found.
Error: C:\Program Files\Borland\Delphi 3\Unit1.pas(25): 'OF' expected but 'IMPLEMENTATION' found.

Does anyone know what my problem ?
 
You didn't declare the size!!!

a: array [1..10] of Steven van Els
SAvanEls@cq-link.sr
 
Apparently dynamic arrays aren't supported pre-Delphi 4.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top