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