Delphi / Object Pascal · Exception

EIntfCastError Exception

What does EIntfCastError Exception mean in Delphi / Object Pascal?

Raised when an illegal cast is attempted on an interface reference - for example using 'as' to cast a variable to an interface the underlying object doesn't implement.

EIntfCastError ExceptionDelphi (VCL) · Delphi (FireMonkey)

Condition

Raised when an illegal cast is attempted on an interface reference - for example using 'as' to cast a variable to an interface the underlying object doesn't implement.

Fix

Use Supports() to test for interface support and get a safely-typed reference back instead of an unconditional 'as' cast, particularly when working with objects obtained from a factory or plugin boundary where the concrete type isn't guaranteed.

Related exception