janko.kaljevic wrote:This implementation would require dynamic arrays and they must be in RAM. So there is no way to declare constant array like this.
This doesn't seem to be the problem here - all
constants are available at compile time. Looking at present compiler possibilities, what Dany asks for is more change of notation, than something really new.
Please notice, that it doesn't matter what size of constant array is declared as external. The size is determined by the declaration in a parent unit/main and it cannot be any other way (if both sizes were to be taken into account, discrepancies would have to lead to an error, so it would be one size anyway).
One may already declare
Code: Select all
const ArraySize: byte; external;
const MyArray: array[1] of byte; external; // size given here is not decisive
and, in the parent unit
Code: Select all
const ArraySize=5;
const MyArray: array[ArraySize] of byte=(0,1,2,3,4);
which in effect produces constant array of 5 elements. And one may now use ArraySize as size of MyArray in the child unit, though it would be better if SizeOf could produce valid result, as well.
The notation proposed by Dany
Code: Select all
const ArraySize: byte; external;
const MyArray: array[ArraySize] of byte; external;
is actually showing a way for easy implementation of proper operation of SizeOf in such cases. (Naturally, in some future, SizeOf should produce valid results, whatever the notation, and there should be no need to provide sizes with no real meaning in external declarations.)