HomeDelphiDelphi Error – E2016 Array type required

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 X2421 Imported identifier ‘%s’ conflicts with ‘%s’ in ‘%s’ Reason for the Error & Solution This occurs...
Delphi Compiler Error X2367 Case of property accessor method %s.%s should be %s.%s Reason for the Error & Solution No...
Delphi Compiler Error X2269 Overriding virtual method ‘%s.%s’ has lower visibility (%s) than base class ‘%s’ (%s) Reason for the...