Ste*_*eve 5 delphi generics interface delphi-xe3
在C#中,我可以创建一个包含特定接口的通用列表,例如:
myList = List<IMyInterface>;
Run Code Online (Sandbox Code Playgroud)
我可以在Delphi XE3中做同样的事情,如果是这样的话怎么样?
我知道我可以创建一个TInterfaceList来存储接口列表,但它不是强类型的,所以我仍然需要在列表中使用对象时进行转换.
有一种强烈的打字方式吗?
klu*_*udg 15
Delphi支持通用List类TList<T>,可以与特定接口一起使用,例如:
var
List: TList<IMyInterface>;
begin
List := TList<IMyInterface>.Create;
{..Do something with list..}
List.Free;
end;
Run Code Online (Sandbox Code Playgroud)