Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does reference counting still works with Delphi Interfaces when you don't provide a guid?

Tags:

delphi

I have the following interface:

type IDataAccessObject<Pk; T:class> = interface
   getByPrimaryKey(key: PK) : T;
   //... more methods
end;

And an implementation of the interface as follows:

type TMyClassDAO = class(TInterfacedObject, IDataAccessObject<integer, TMyClass>)
   getByPrimaryKey(key:integer) : TMyClass;
   // more methods
end;

Note that I am not providing a guid for the interface (because every instantiation of the previous generic interface is a different interface and they should not share the same guid). However I am not sure whether that does not break reference counting implemented by TInterfacedObject?

like image 327
BigONotation Avatar asked May 25 '17 11:05

BigONotation


1 Answers

Reference counting does not rely on a GUID, but on _AddRef() and _Release() method implementations.

Since you inherit from TInterfacedObject, reference counting will work for all of your object instances.

The only thing you lose if you don't provide a GUID is the ability to query one interface from another, such as in calls to the Supports() function, QueryInterface() interface method, and the is and as operators.

like image 133
Dalija Prasnikar Avatar answered Oct 20 '22 23:10

Dalija Prasnikar