[fpc-devel] {$Interfaces Corba} and TInterfacedObject

Thorsten Engler thorsten.engler at gmx.net
Thu Nov 29 14:36:32 CET 2007


> IMO borland screwed up here when they introduced IInterface = 
> IUnknown.
No they didn't.

> 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;

Beside that, that's the point of such a castrated Iinterface? What can you
do with it? No QueryInterface, so you can't get from there to anything else.
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. 

Cheers,
Thorsten




More information about the fpc-devel mailing list