[fpc-pascal] How to allocate a 2D array?
Jilani Khaldi
jilani at cheapnet.it
Mon Jan 12 19:30:41 CET 2009
Arjan van Dijk wrote:
> Hi!
>
> In my code I often use 2D arrays.
> Until today, I kept the maximum dimension fixed to 400 * 300 points.
> How can I make allocatable columns of ARBITRARY size?
>
> For simplicity here a 1D reduction of the problem:
>
> This is what I have:
>
> CONST
> MaxN = 400;
> TYPE
> ColumnType = ARRAY[1..MaxN] OF Float;
You can use a dynamic array.
type
ColumnType = array of float;
var
CT: ColumnType;
begin
SetLength(CT,TheSizeYouWant); // TheSizeYouWant is the number of
elements (an integer)
CT[0] := 3.14159; // the first element has index 0
...
CT[TheSizeYouWant-1] := 2.71828; // the last element;
...
SetLength(CT,0); // set it to nil
end;
--
Jilani KHALDI
---------------------
http://jkhaldi.oltrelinux.com
More information about the fpc-pascal
mailing list