In delphi 2009 I have a reference to a IInterface
which I want to cast to the underlying TObject
Using TObject(IInterface)
obv
You are right. Beginning with Delphi 2010, you are able to use the as operator, e.g. via aObject := aInterface as TObject
or even aObject := TObject(aInterface)
.
This as
operator use a special hidden interface GUID (ObjCastGUID
) to retrieve the object instance, calling an enhanced version of TObject.GetInterface
, which does not exist prior to Delphi 2010. See source code of System.pas
unit to see how it works.
I've published some code working for Delphi 6 up to XE2, including Delphi 2009.
See http://blog.synopse.info/post/2012/06/13/Retrieve-the-object-instance-from-an-interface