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.

Share:

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

Delphi Compiler Error E2313 Attribute – Known attribute cannot specify properties Reason for the Error & Solution No further information...
Delphi Compiler Error E2379 Virtual methods not allowed in record types Reason for the Error & Solution No further information...
Rodrigo , one of the long time Delphi Developer has been working on one of his personal project “Delphi IDE...