[Lazarus] IUnknown and reference counting
Xiangrong Fang
xrfang at gmail.com
Wed Mar 20 15:55:27 CET 2013
As a matter of fact, this is what confused me the most. In my previous
experience, e.g. with java or php, I don't care about COM or CORBA,
interface to me is just another way to implement abstract method for
languages that do not support multiple inheritance. Isn't that the case?
The reason I asked the question initially was I try to implement Enumerator
for my TTreap class so that I can use it in for... in loop. To do this,
can I just implement the GetEnumerator method, or I have to define the
class as this:
generic TTreap<TKey, TValue> = class(IEnumerable);
In another word, if I do not declare that the class implements IEnumerable,
but just add the required method, will the language detect this and make my
class enumerable?
2013/3/20 Graeme Geldenhuys <graeme at geldenhuys.co.uk>
> 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/
>
>
> --
> _______________________________________________
> Lazarus mailing list
> Lazarus at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20130320/cbf469ad/attachment-0003.html>
More information about the Lazarus
mailing list