Re:Delphi - Dynamic 2-dimensional arrays
In article <zsol.7.00866...@mindspring.com>, z...@mindspring.com says...
Quote
>Is it true that Delphi will not allow dynamic 2-dimensional arrays? I f so,
>then what do you do in this case? Can you set 1 dimension as fixed and make
>the other dynamic?
>I've tried the 2-dimensional dynamic and it doesn't work. If anyone has
>experience in this problem and has a suggestion I'd be most appreciative.
well the problem is:
if you have an
test : array[0..0] of longint;
lets say, and you allocate lets say $4000 bytes, the compiler has no trouble converting
test[$200] to a pointer $800 bytes into the array, coz he knows a longint is 4 bytes of
size.
however, if you have
test : array[0..0,0..0] of longint;
the same can't work, because this is in fact identical to
test : array[0..0] of array[0..0] of longint;
so you have an array of arrays, not of longints. and if the compiler does not know what size
the inner array has (the array of longint), he cannot access a certain value in the outer
array (array of array)
so therefor there are no two- (or more-) dimensional arrays that are dynamic in any dimension
other then the outermost. never will be, either. it's a no-go.
you CAN of course make a
test : array[0..0,0..$3f] of longint;
coz this equals
test : array[0..0] of array[0..$3f] of longint;
and array[0..$3f] of longint has a fixed size of $100.
now...how do we work around this?
easy. we just make one huge array (huge of course being relative as long as Delphi95 isn't out
:), and keep width as an constant.
so if you want to access test[x,y] you do this with
test[x+width*y];
assuming y is starting at 0.
thanx for your attention
marc