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