Pascal doesn't support variable-sized arrays declared as fixed-length.
Most modern compilers (Delphi/FreePascal) support dynamic arrays, where the length is set at runtime. The lower bound is always zero, and the upper bound is length - 1:
var
Arr: array of Integer;
L, H, Len: Integer;
ArraySize: Integer;
begin
Len := 10; // Value of Len can be input at runtime
SetLength(Arr, Len);
L := Low(Arr); // Will be 0
H := High(Arr); // Will be Len - 1, because first index is 0
ArrSize := Length(Arr); // Will be Len
WriteLn('Low: ', L, ' High: ', H, ' Length: ', ArrSize);
ReadLn;
end;
Here's a complete sample (in Delphi, but it should work with FreePascal) that accepts input from the console and uses it to set the length, and show you the low, high, and length values like above. It also demonstrates how to pass the array to a procedure that has no knowledge of the number of elements in the array.
program Project1;
uses
SysUtils;
// Lists the items in an array to the console without
// knowing in advance the size of the array
procedure ListAnArray(const TheArray: array of Integer);
var
x: Integer;
begin
// Retrieve the valid low and high indexes, and
// loop through the array to output each value
for x := Low(TheArray) to High(TheArray) do
WriteLn('TheArray ', x, ' value: ', TheArray[x]);
end;
// The variables we'll be using (a few more than I would
// normally use, just to make the example clearer)
var
ArraySize: Integer; // Length of array input by user
lowIdx, highIdx: Integer; // low array index, high index
ArrayLen: Integer; // Length of array (set at runtime)
Counter: Integer; // Loop counter
TestArray: array of Integer; // Our dynamic array
begin
Write('Enter array length: '); // Prompt user
Readln(ArraySize); // Read input
Writeln('You entered: ', ArraySize);
WriteLn(''); // Blank line separator
SetLength(TestArray, ArraySize); // Size the array
lowIdx := Low(TestArray); // Get low index (always 0)
highIdx := High(TestArray); // # of elements - 1
ArrayLen := Length(TestArray); // Same as user entered
Writeln('Low: ', lowIdx, // Output what we've learned
' High: ', highIdx,
' Length: ', ArrayLen);
WriteLn(''); // Blank line separator
for Counter := lowIdx to highIdx do // Fill the array with values
TestArray[Counter] := Counter * Counter;
ListAnArray(TestArray); // Pass array to procedure
WriteLn(''); // Blank line separator
WriteLn('Press Enter to quit...'); // Pause to allow reading.
Readln;
end.