Dynamic Arrays

Declare a dynamic array without providing the bounds that are necessary for a static array declaration then use the SetLength procedure to set its size. A dynamic array is always zero-based. A simple example follows. The Conversion and ArrayToFile procedures in the demonstrations at the end of this tutorial illustrate more realistic uses.

program DynamicArrayDemo;
  NumOfValues : integer;
  CircleAreas : array of real;
  i : integer;

  writeln('This program will store temporarily the values of the area' +
          'of circles having integer values for the radius then display them.');
  write('How many values? ');
  SetLength(CircleAreas, NumOfValues);
  for i := 0 to NumOfValues - 1 do
    CircleAreas[i] := pi * i * i;
  for i := 0 to NumOfValues - 1 do
    writeln('A circle of radius ',i , ' cm has area ',
             CircleAreas[i] : 18 : 6, ' sq cm.');
Programming - a skill for life!

Further ways of using arrays for confident programmers