This task is about arrays.

For hashes or associative arrays, please see Creating an Associative Array.

For a definition and in-depth discussion of what an array is, see Array.



Task

Show basic array syntax in your language.

Basically, create an array, assign a value to it, and retrieve an element   (if available, show both fixed-length arrays and
dynamic arrays, pushing a value into it).

Please discuss at Village Pump:   Arrays.

Please merge code in from these obsolete tasks:

   Creating an Array
   Assigning Values to an Array
   Retrieving an Element of an Array


Related tasks

   Collections
   Creating an Associative Array
   Two-dimensional array (runtime)


 
procedure TForm1.Button1Click(Sender: TObject);
var
  StaticArray: array[1..10] of Integer; // static arrays can start at any index
  DynamicArray: array of Integer; // dynamic arrays always start at 0
  StaticArrayText,
  DynamicArrayText: string;
  ixS, ixD: Integer;
begin
  // Setting the length of the dynamic array the same as the static one
  SetLength(DynamicArray, Length(StaticArray));
  // Asking random numbers storing into the static array
  for ixS := Low(StaticArray) to High(StaticArray) do
  begin
    StaticArray[ixS] := StrToInt(
      InputBox('Random number',
               'Enter a random number for position',
               IntToStr(ixS)));
  end;
  // Storing entered numbers of the static array in reverse order into the dynamic
  ixD := High(DynamicArray);
  for ixS := Low(StaticArray) to High(StaticArray) do
  begin
    DynamicArray[ixD] := StaticArray[ixS];
    Dec(ixD);
  end;
  // Concatenating the static and dynamic array into a single string variable
  StaticArrayText := '';
  for ixS := Low(StaticArray) to High(StaticArray) do
    StaticArrayText := StaticArrayText + IntToStr(StaticArray[ixS]);
  DynamicArrayText := '';
  for ixD := Low(DynamicArray) to High(DynamicArray) do
    DynamicArrayText := DynamicArrayText + IntToStr(DynamicArray[ixD]);
  end;
  // Displaying both arrays (#13#10 = Carriage Return/Line Feed)
  ShowMessage(StaticArrayText + #13#10 + DynamicArrayText);
end;