In Delphi 2010, ho definito un TInterfaceList generica come segue:È possibile utilizzare TInterfaceList generico Delphi?
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;
non ho ancora avuto alcun problema, ma c'è qualcosa di intrinsecamente rischioso a fare questo? Sarebbe possibile aggiungere un enumeratore per consentire a..in loop di lavorarci sopra? Se non c'è niente di sbagliato in questo, mi chiedo perché qualcosa di simile non sia già definito nella RTL.