[Lazarus] How to cast a Interface to a Object in Lazaeus

Dmitry Boyarintsev skalogryz.lists at gmail.com
Fri Mar 13 14:35:51 CET 2015


On Fri, Mar 13, 2015 at 5:49 AM, aradeonas <aradeonas at operamail.com> wrote:

> OK,So in the end how can I cast a Interface to a Object in Lazarus?
>

The syntax show here:
http://docwiki.embarcadero.com/RADStudio/XE7/en/Interface_References#Casting_Interface_References_to_Objects
works in FPC as well.

 var
   LIntfRef: IInterface;
   LObj: TInterfacedObject;
 begin
   { Create an interfaced object and extract an interface from it. }
   LIntfRef := TInterfacedObject.Create();

   { Cast the interface back to the original object. }
   LObj := LIntfRef as TInterfacedObject;
 end

BUT, it would only work, if you're using COM interfaces (wont work corba).
It works for COM interfaces only because FPC just checks that an interface
implements IObjectInstance (via COM queryinterface method).

IObjectInstance: TGuid = '{D91C9AF4-3C93-420F-A303-BF5BA82BFD23}';

All pascal objects implement it, thus you don't have to specify it
implicitly.

If you're not using COM interfaces, then you'll need to add getObject()
method to your interface.

thanks,
Dmitry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20150313/8b60a912/attachment-0003.html>


More information about the Lazarus mailing list