[Lazarus] IUnknown and reference counting

Graeme Geldenhuys graeme at geldenhuys.co.uk
Wed Mar 20 15:46:38 CET 2013


Hi,

Dodi covered it all pretty much...

On 2013-03-20 13:38, Xiangrong Fang wrote:
> 
> So, what is the purpose of this UUID and the method provided by
> TInterfacedObject?

Only needed if you are doing COM programming under Windows. For the rest
of the times you don't need it.

Also note that sometimes it is beneficial having interface support, but
without reference counting. In that case you can use CORBA-style interfaces.

Simply add the following to your unit..

{$mode objfpc}{$H+}
{$interfaces corba}     // <<--   New line

type
  ITestInterface = interface
    [STestInterface]
    procedure DoSomething;
    procedure DoItAll;
  end;


Now 'interface' in the type declaration will not be a IUnknown or
IInterface descendant. Thus no need to use TInterfacedObject as a base
class, TObject will suffice. I tend to use CORBA-style interfaces much
more in my applications - it allows me to easily add interface support
to any of my existing classes.

I also believe that you can mix COM and CORBA style interfaces in your
application, but that is probably not a good idea. Best to avoid that.



Regards,
  - Graeme -

-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/





More information about the Lazarus mailing list