Delphi Error – E2089 Invalid typecast

Delphi Compiler Error

E2089 Invalid typecast

Reason for the Error & Solution

This error message is issued for type casts not allowed by the rules. The following kinds of casts are allowed:

– Ordinal or pointer type to another ordinal or pointer type

– A character, string, array of character or pchar to a string

– An ordinal, real, string or variant to a variant

– A variant to an ordinal, real, string or variant

– A variable reference to any type of the same size.

Note that casting real types to integer can be performed with the standard functions Trunc and Round.

There are other transfer functions like Ord and Chr that might make your intention clearer.

program Produce;

begin
  Writeln( Integer(Pi) );
end.

This programmer thought he could cast a floating point constant to Integer, like in C.

program Solve;

begin
  Writeln( Trunc(Pi) );
end.

In the Delphi language, we have separate Transfer functions to convert floating point values to integer.

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