Does link counting still read with Delphi interfaces if you don't provide a guide?

I have the following interface:

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

And the interface implementation is 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 (since each instantiation of the previous common interface represents a different interface, and they should not use the same guid ). However, I'm not sure if this does not break the reference count implemented by TInterfacedObject ?

+5
source share
1 answer

Reference counting is not based on the GUID , but on the implementations of _AddRef() and _Release() .

Since you are inheriting from TInterfacedObject , reference counting will work for all your object instances.

The only thing you lose if you do not provide a GUID is the ability to request one interface from another, for example, when you call the Supports() , QueryInterface() and is and as functions.

+15
source

Source: https://habr.com/ru/post/1268227/


All Articles