SRL Archive - OSR Help

Multidimensional Arrays?


Chen Monopoly

2012-05-14 19:26:25

How do I do multidimensional arrays?

Like.. I want to do a 2D or 3D array, how would I do that?
I tried googling it and got

Var
my2DArray : Array[1..3][1..5] of Byte;
Begin
my2DArray[2][4] := 10;
End
but apparently that doesn't compile because its expecting an 'of' between [1..3] and [1..5]

Janilabo

2012-05-14 19:36:55

Needs to be like this:

var
my2DArray: array[1..3] of array[1..5] of Byte;

begin
my2DArray[2][4] := 10;
end.

Sin

2012-05-14 19:39:48

I'm wondering what you're using this for haha.

Janilabo

2012-05-14 19:43:55

By the way, I recommend you use something like this:

var
my2DArray: array[1..3] of array of Byte;
a, b, c: Integer;

begin
ClearDebug;
my2DArray[1] := [0, 1, 2, 3, 4];
my2DArray[2] := [5, 6, 7, 8, 9];
my2DArray[3] := [10, 11, 12, 13, 14];
// Lets print it:
for a := 1 to 3 do
begin
c := High(my2DArray[a]);
for b := 0 to c do
WriteLn('my2DArray[' + IntToStr(a) + '][' + IntToStr(b) + ']: ' + IntToStr(my2DArray[a][b]));
end;
end.

Chen Monopoly

2012-05-14 20:50:29

Okay thanks.