Delphi Error – E2016 Array type required

Delphi Compiler Error

E2016 Array type required

Reason for the Error & Solution

This error message is given if you either index into an operand that is not an array, or if you pass an argument that is not an array to an open array parameter.

program Produce;
var
  P: ^Integer;
  I: Integer;
begin
  Writeln(P[I]);
end.

We try to apply an index to a pointer to integer – that would be legal in C, but is not in Delphi.

program Solve;
type
  TIntArray = array [0..MaxInt DIV sizeof(Integer)-1] of Integer;
var
  P: ^TIntArray;
  I: Integer;
begin
  Writeln(P^[I]);   (*Actually, P[I] would also be legal*)
end.

In the Delphi language, we must tell the compiler that we intend P to point to an array of integers.