Delphi Error – E2072 Number of elements (%d) differs from declaration (%d)

Delphi Compiler Error

E2072 Number of elements (%d) differs from declaration (%d)

Reason for the Error & Solution

This error message appears when you declare a typed constant or initialized variable of array type, but do not supply the appropriate number of elements.

program Produce;

var
  A : array [1..10] of Integer = (1,2,3,4,5,6,7,8,9);

begin
end.

The example declares an array of 10 elements, but the initialization only supplies 9 elements.

program Solve;

var
  A : array [1..10] of Integer = (1,2,3,4,5,6,7,8,9,10);

begin
end.

We just had to supply the missing element to make the compiler happy. When initializing bigger arrays, it can be sometimes hard to see whether you have supplied the right number of elements. To help with that, you layout the source file in a way that makes counting easy (e.g. ten elements to a line), or you can put the index of an element in comments next to the element itself.

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...