[Lazarus] How to cast a Interface to a Object in Lazaeus
skalogryz.lists at gmail.com
Fri Mar 13 15:52:25 CET 2015
On Fri, Mar 13, 2015 at 10:21 AM, Graeme Geldenhuys <
mailinglists at geldenhuys.co.uk> wrote:
> Sorry, but that is a false statement. It works for both COM and CORBA
> interfaces. Simply don't use the 'as' syntax - just cast it.
Wait, how can a syntax "work", if not used? :)
Don't forget that Pascal is safe-type language.
So "as" has also intent of checking an interface for being castable to an
If an interface is originating from non-FPC environment (i.e. delphi, c++
or whatever langauge) such casting should fail.
This is not the case for OP, but should be used as good practices.
Please note that casting Interface to TObject via "as" was not originally
in the compiler. It was eventually added for Delphi compatibility.
Previously compiler would just fail with an error that interface is not
castable to object at all (I.e. Delphi 7 won't allow the syntax as well)
P.S. By the way, if different versions of FPC are used (i.e. an interface
is loaded from a DLL) and then interface is typecasted to an object via
"as". It might cause problems if TObject structures are different between
host application and the library. But using interfaces only prevents the
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Lazarus