Object of the <Class1Name> Class cannot be Cast to the <Class2Name> Class

Description

An attempt to cast two objects with incompatible classes is made in the code. The class of the object that is cast to another class does not inherit from it.

Troubleshooting Tips

Check classes of the cast objects. Class inheritance may be specified incorrectly.

Example

Class A: Object
    
End Class A;

Class B: Object
    
End Class B;

Sub UserProc;
Var
    Obj1: A;
    Obj2: B;
Begin
    Obj1 := Obj2 As A;
End Sub UserProc;

When the specified code is compiled, the string Obj1 := Obj2 As A; displays the following error: An object of the B class cannot be cast to the A class. The error occurs because the B class does not inherit from the A class and direct transformation is impossible.

See also:

Compiler Messages