Hello everyone,
I am wondering if the usage of a generic TList<T>
where T
is any interface type (except IUnknown
/IInterface
) might be dangerous. I am heavily using interfaces and store them in lists. Some interfaces are my own, some are provided by some COM-interfaces, so COM is involved.
I see a potential problem where checks for instance-equality happens, e.g. when I use the Remove
method of the list (which internally needs to compare my provided value to the contained values). According to COM-rules you can only compare two interfaces for equality after casting them to IUnknown
. I don't know if the default comparator involved in finding my interface in the TList<T>
is aware of that.
To illustrate my question with an example:
var
list:TList<IMyInterface>;
intf:IMyInterface;
begin
...
list:=TList<IMyInterface>.Create;
list.Add(intf);
...
list.Remove(intf);
end;
Is the above code legitimate?