SRL Archive - Help and Support

How do I set the length of a 2D Array?


R0b0t1

2007-12-02 19:08:49

This, for example, does not work.


program New;
var
ColorArray: T2DIntArray;
X, Y, I: Integer;

begin
SetArrayLength(ColorArray, 100);
for I:= 0 to 100 do //We need to set the length of the arrays
SetArrayLength(ColorArray[I], 100);
for X:= 0 to 100 do //If you happen to know the size before hand.
for Y:= 0 to 100 do //X loop is first, then Y.
WriteLn('ColorArray['+IntToStr(X)+']['+IntToStr(Y)+']:= '+
IntToStr(ColorArray[X][Y]));
end.

?

EDIT: Forget that I didn't give the array values.

XcanadamanX

2007-12-02 20:37:06

program New;
var
ColorArray: Array[0..100] of Array[0..100] of Integer;
X, Y, I: Integer;

begin
for X:= 0 to 100 do //If you happen to know the size before hand.
for Y:= 0 to 100 do //X loop is first, then Y.
WriteLn('ColorArray['+IntToStr(X)+']['+IntToStr(Y)+']:= '+
IntToStr(ColorArray[X][Y]));
end.

R0b0t1

2007-12-02 21:10:19

Its not possible to do that for my uses. Any other suggestions?




EDIT: I got it… Went to 100 instead of 99.

Smartzkid

2007-12-02 21:17:24

Lol, R0b0t, just a small mistake:

program New;
var
ColorArray: T2DIntArray;
X, Y, I: Integer;

begin
SetArrayLength(ColorArray, 101);
for I:= 0 to 100 do //We need to set the length of the arrays
SetArrayLength(ColorArray[i], 101);
for X:= 0 to 100 do //If you happen to know the size before hand.
for Y:= 0 to 100 do //X loop is first, then Y.
WriteLn('ColorArray['+IntToStr(X)+']['+IntToStr(Y)+']:= '+
IntToStr(ColorArray[X][Y]));
end.

I'm sure you know about array indexes and all that, how they start at 0 and whatnot…