Reputation: 816
I would like to define a list type for a generic interface. It is needed for a tree implementation that stores generic typed data. Unfortunately, the trivial solution does not work:
uses
Generics.Collections;
type
ITreeNode<T> = interface;
TTreeNodeList<T> = TList<ITreeNode<T>>;
ITreeNode<T> = interface
['{BC384FDB-4509-44D3-8946-E7ECD4417C4D}']
//...
function getChildNodes : TTreeNodeList<T>;
function getData : T;
end;
TTreeNode<T> = class ( TInterfacedObject, ITreeNode<T> )
//...
end;
procedure foo;
var
node : ITreeNode<cardinal>;
begin
node := TTreeNode<cardinal>.create;
//...
end;
Is there any trick to implement it?
Upvotes: 2
Views: 426
Reputation: 816
OK. I found the solution:
TTreeNodeList<T> = class ( TList<ITreeNode<T>> )
end;
and not
TTreeNodeList<T> = TTreeNodeList<ITreeNode<T>>;
Upvotes: 5