如何将泛型存储在非泛型对象持有的泛型TList中?
type
TXmlBuilder = class
type
TXmlAttribute<T>= class
Name: String;
Value: T;
end;
TXmlNode = class
Name: String;
Attributes: TList<TXmlAttribute<T>>;
Nodes: TList<TXmlNode>;
end;
...
end;编译器说T没有被删除
Attributes: TList<TXmlAttribute<T>>;--皮埃尔·亚格
发布于 2010-01-26 18:43:02
TXmlNode不知道T是什么。它应该是什么?
也许你的意思是:
TXmlNode<T> = class
Name: String;
Attributes: TList<TXmlAttribute<T>>;
Nodes: TList<TXmlNode<T>>;
end;..。或者您需要指定一个类型。
但是,您似乎在这里遗漏了一些东西。泛型允许您为每种类型创建单独的类,而不是为所有类型创建一个类。在上面的代码中,TList保存了一个类型数组,这些类型具有不同的,而您可能希望它们具有不同的。请考虑以下内容:
TXmlBuilder = class
type
TXmlAttribute= class
Name: String;
Value: Variant;
end;
TXmlNode = class
Name: String;
Attributes: TList<TXmlAttribute>;
Nodes: TList<TXmlNode>;
end;
...
end;https://stackoverflow.com/questions/2138800
复制相似问题