【发布时间】:2010-02-09 11:45:28
【问题描述】:
在 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;
我还没有遇到任何问题,但是这样做有什么固有的风险吗?是否可以向它添加一个枚举器以允许 for..in 循环对其进行处理?如果没有问题,我想知道为什么 RTL 中还没有定义类似的东西。
【问题讨论】:
标签: delphi delphi-2010