Ala*_*ark 7 delphi delphi-2010
在Delphi 2010中,我定义了一个通用的TInterfaceList,如下所示:
type
TInterfaceList<I: IInterface> = class(TInterfaceList)
function GetI(index: Integer): I;
procedure PutI(index: Integer; const Item: I);
property Items[index: Integer]: I read GetI write PutI; default;
end;
implementation
function TInterfaceList<I>.GetI(index: Integer): I;
begin
result := I(inherited Get(Index));
end;
procedure TInterfaceList<I>.PutI(index: Integer; const Item: I);
begin
inherited Add(Item);
end;
Run Code Online (Sandbox Code Playgroud)
我还没有遇到任何问题,但这样做有什么本质上的风险吗?是否可以向其添加枚举器以允许..in循环对其进行操作?如果它没有任何问题,我想知道为什么在RTL中还没有定义类似的东西.