Delphi Error – E2010 Incompatible types – ‘%s’ and ‘%s’

Delphi Compiler Error

E2010 Incompatible types – ‘%s’ and ‘%s’

Reason for the Error & Solution

This error message results when the compiler expected two types to be compatible (or similar), but they turned out to be different.

In general, you have to look at your program very carefully to decide how to resolve type incompatibilities.

If you receive the following error message:

[DCC Error] Project1.dpr(8): E2010 Incompatible types: 'Integer' and 'Extended'

The first type in this message (Integer) is the type expected, and the second type (Extended) is the type that was given. An Extended type cannot be accommodated as an Integer.

Here is another example:

 
 program Produce;
 
 procedure Proc(I: Integer);
 begin
 end;
 
 begin
   Proc( 22 / 7 ); (*Result of / operator is Real*)
 end.

The programmer thought the division operator /, which is used in C++, would yield an integral result — but this is not the case in Delphi.

The solution in this case is to use the integral division operator div:

  
 program Solve;
 
 procedure Proc(I: Integer);
 begin
 end;
 
 begin
   Proc( 22 div 7 ); (*The div operator gives result type Integer*)
 end.

Other examples include:

  • with pointer incompatible with ^Integer
  • Generics: Object<T1> incompatible with TObject<T2>

See Also

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