BigONotation
BigONotation

Reputation: 4538

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

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?

Upvotes: 5

Views: 189

Answers (1)

Dalija Prasnikar
Dalija Prasnikar

Reputation: 28530

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.

Upvotes: 15

Related Questions