Vadik
asked on
Dynamic array dimention
How to create array with dynamic dimention ? Size of array will be defined only after program start.
? use a vararray or a tlist or a tstringlist or a hidden tstringgrid
Just an example
var a: array of Byte;
i: Integer;
begin
Randomize;
SetLength(a, 25); // set size to 25 bytes
for i := Low(a) to High(a) do // itterate the entire array
a[i] := Random(100);
end;
var a: array of Byte;
i: Integer;
begin
Randomize;
SetLength(a, 25); // set size to 25 bytes
for i := Low(a) to High(a) do // itterate the entire array
a[i] := Random(100);
end;
if you have D4 and above....
//======================== =====
interface
type
TMyGrid = array of array of Integer;
var
MyGrid: TMyGrid; // declares a two-dimensional array of integers.
implementation
// To instantiate, call SetLength with two integer arguments.
// For example, if x and y are integer-valued variables,
// SetLength(Grid, x, y);
// allocates an x-by-y array, and MyGrid[0, 0] denotes an element of the array.
// MyGrid := nil; // deallocates mem
//======================== =====
Steve
//========================
interface
type
TMyGrid = array of array of Integer;
var
MyGrid: TMyGrid; // declares a two-dimensional array of integers.
implementation
// To instantiate, call SetLength with two integer arguments.
// For example, if x and y are integer-valued variables,
// SetLength(Grid, x, y);
// allocates an x-by-y array, and MyGrid[0, 0] denotes an element of the array.
// MyGrid := nil; // deallocates mem
//========================
Steve
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thank you all!
Glad to be of service :)
GL
Mike
GL
Mike
Nice one edey!