For interfaces, you'll want to use the PTypeInfo pointer, which is returned by the TypeInfo compiler magic function. PTypeInfo is declared in the TypInfo module.
type
TInterfaceDictionary = TObjectDictionary<PTypeInfo, TObject>;
var
d: TInterfaceDictionary;
myObject: TSomeImplementation;
begin
d := TInterfaceDictionary.Create([doOwnsValues]);
d.Add(TypeInfo(ISomeInterface), TSomeImplementation.Create());
myObject = d[TypeInfo(ISomeInterface)];
end;
Of course, if these were classes instead of interfaces, you could just use the TClass link.
source
share