A: Declaring a variable of type : array [0..0] allows you to dynamically allocate the array on the heap and then access the elements of the array with a subscript. Consider the following:
{$R-} {range checking has to be off or the compiler will complain}
type
MyRecordType = record
Field1 : integer;
Field2 : word;
end;
StructArr = array [0..0] of MyRecordType;
MyStructPtr = ^StructArr;
var
myPtr : MyStructPtr;
iNumberOfElements : word;
TheNthElement : integer;
begin
{Set the number of elements you want}
iNumberOfElements := SomeArbitraryValueDeterminedAtRuntime;
{Allocate the RAM}
GetMem(myPtr, iNumberOfElements * SizeOf(MyRecordType));
{Now you have a dynamic array of StructArr[0..iNumberOfElements-1].
That is, you didn't have to declare the number of
elements until
runtime.}
try
{The Nth element is...}
TheNthElement := myPtr^[TheNthElementIndex].Field1;
{
^^^^^^^^^^^^^^^^^^^ }
{That array[0..0] declaration makes ^this^
possible. }
{...and it *must* be a variable. Constants
will cause a range error.}
finally
FreeMem(myPtr, SizeOf(MyRecordType) * SomeArbitraryValueDeterminedAtRuntime);
end;
end;
Very useful when you want an array, but don't know how many elements
you ar going to put in it.