Link to home
Create AccountLog in
Avatar of Vadik
Vadik

asked on

Dynamic array dimention

How to create array with dynamic dimention ? Size of array will be defined only after program start.
Avatar of kretzschmar
kretzschmar
Flag of Germany image

? use a vararray or a tlist or a tstringlist or a hidden tstringgrid
Avatar of Epsylon
Epsylon

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;
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
ASKER CERTIFIED SOLUTION
Avatar of edey
edey

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Vadik

ASKER

Thank you all!
Glad to be of service :)


GL
Mike
Nice one edey!