delphi - How to set multiple array fields at once without using a for loop in pascal? -
i learning pascal , stuck problem concerning array manipulation. have come across method of setting arrays, have seen in other languges, not know how similar in pascal.
the declaration of variable looks this:
rotationbounds: array of array of integer; setlength(rotationbounds, 5, 5);
and want this:
rotationbounds := [ [0, 0, 0, 0, 0], [0, 1, 1, 0, 0], [0, 0, 1, 0, 0], [0, 0, 1, 1, 0], [0, 0, 0, 0, 0], ];
basically, trying set multi-dimentional array directly, rather looping through it.
one of focuses make picture, easy read , understand.
is there way achieve this?
i using borland delphi 6 compiler progam.
in delphi 6 there no built in support dynamic array initialization. i'd use pair of helper functions this:
type tintegerarray = array of integer; tintegermatrix = array of tintegerarray; function integerarray(const values: array of integer): tintegerarray; var i: integer; begin setlength(result, length(values)); := 0 high(result) result[i] := values[i]; end; function integermatrix(const values: array of tintegerarray): tintegermatrix; var i: integer; begin setlength(result, length(values)); := 0 high(result) result[i] := values[i]; end;
and call this:
var rotationbounds: tintegermatrix; .... rotationbounds := integermatrix([ integerarray([0, 0, 0, 0, 0]), integerarray([0, 1, 1, 0, 0]), integerarray([0, 0, 1, 0, 0]), integerarray([0, 0, 1, 1, 0]), integerarray([0, 0, 0, 0, 0]), ]);
Comments
Post a Comment