[fpc-devel] {$Interfaces Corba} and TInterfacedObject
Marc Weustink
marc.weustink at cuperus.nl
Thu Nov 29 16:46:27 CET 2007
Thorsten Engler wrote:
>> IMO borland screwed up here when they introduced IInterface =
>> IUnknown.
> No they didn't.
IMO :)
>> It was IMo cleaner (and you can mix interface types)
> There are no different "types" of interfaces in Delphi/Kylix. Even if there
> were (like there are in FPC) you can never ever mix them.
>
>> when they declared it like:
>>
>> type
>> IInterface = interface
>> end;
>>
>> IUnknown = interface(IInterface)
>> _addref...
>> _release....
>> Query....
>> end;
>
> Lets assume we had that definition. Now look at this code:
>
> Var
> Intf : Iinterface;
> Unk : Iunknown;
> Begin
> Unk := //... Get some Iunknown from somewhere
> Intf := Unk; //would be valid as Iunknown derives from Iinterface
> //but as Intf doesn't have an AddRef it can't be called.
> Unk := nil; //Unk has _release which is called and frees the object behind
> the interface)
> //Intf now points to a freed object
> End;
True, you need to know what you are doing. It is the same as P:
Pointer; P ;= Unk;
(OK accessing methods is more dificult)
> Beside that, that's the point of such a castrated Iinterface? What can you
> do with it?
The same what you want to do with a CORBA interface ?
> No QueryInterface, so you can't get from there to anything else.
You can say the same one you have assigned an object to an interface, no
way back to the object. So once you assign a iunkown or object to the
stripped iinterface you can only stay there.
If you didn't want that, you shouldn't have used a iinterface in the
first place (or cast it as you would have done with a pointer).
> The as and is operators depend on either methods of Tobject (which can't be
> reached) or information which is stored at negative offset in the VMT (which
> isn't present for an interface VMT) so they can't be used either.
You can do 'is' and 'as' on IUnknown descendants now only too, so no
difference.
The only advantage is that you *can* mix reference counted and non
reference counted interfaces, where the non reference counted don't
require the overhead of an additional exception handler.
There are cases I only want the polymorf behaviour of interfaces and not
the refercing
Marc
More information about the fpc-devel
mailing list