[Lazarus] IUnknown and reference counting
Graeme Geldenhuys
graeme at geldenhuys.co.uk
Mon Mar 25 02:52:35 CET 2013
On 2013-03-21 20:48, Hans-Peter Diettrich wrote:
> Sven Barth schrieb:
>> On 21.03.2013 21:14, Hans-Peter Diettrich wrote:
>>> Sven Barth schrieb:
>>>
>>>> > Thanks for giving me insight into the crippled implementation of
>>>> interfaces in FPC :-]
>>>>
>>>> Why crippled?
>>>
>>> When FPC does not allow to use delegation ("implements") together with
>>> implementing selected methods, this feature is of no practical use :-(
>>
>> There exists at least a bug report about it:
>> http://bugs.freepascal.org/view.php?id=16531 :)
>
> +1
>
>>> Also the hype about CORBA interfaces looks like mere eye-candy or
>>> obfuscation to me. Delphi interfaces require neither COM nor CORBA, they
>>> are only open in either direction.
>>
>> But some people don't like the reference counting. They want to use
>> interfaces like in other languages to just define a "interface" to a class.
>
> Since reference counting must be implemented,
Why *must* reference counting be implemented when you want to use
Interfaces? Many other languages also have interfaces with no reference
counting.
The CORBA-style interfaces that FPC support also make descendant classes
easier to extend. For example
// this class is supplied by a 3rd party company.
TMyClass = class(TObject)
...
end;
Now I want to add some functionality to a descendant class in my
project, and use interfaces to do it [for whatever reason I see fit]. No
problem.
TMySuperClass = class(TMyClass, IObserver)
private
// implement IObserver methods here
end;
All done!
If reference counting interfaces was the only option, I would be forced
to implement IUnknown in the TMySuperClass class.... for what? TMyClass
is not a TInterfacedObject descendant, and the 3rd party vendor never
had a need for interfaces, so they used the very common TObject base
class. I don't need reference counting just to have interfaces support -
so based on what you say, reference counting must be forced upon me! And
I must do more work in my class by adding IUnknown to the TMySuperClass too.
Regards,
- Graeme -
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/
More information about the Lazarus
mailing list