Oh das hätte ich machen sollen.
Ich benutze Delphi 7.
Delphi 7 kennt noch keine Generics, da muss man dann mehr von Hand machen.
Delphi-Quellcode:
type
TFeld = class;
TFeldList = class;
TFeldListEnumerator = record
constructor Create(AList: TFeldList);
private
FIndex: Integer;
FList: TFeldList;
function GetCurrent: TFeld;
public
function MoveNext: Boolean;
property Current: TFeld read GetCurrent;
end;
TFeldList = class(TObjectList)
protected
function GetItem(Index: Integer): TFeld;
procedure SetItem(Index: Integer; AObject: TFeld);
public
function GetEnumerator: TFeldListEnumerator;
property Items[AIndex: Integer]: TFeld read GetItem write SetItem; default;
end;
implementation
{ TFeldList }
function TFeldList.GetEnumerator: TFeld;
begin
Result := TFeldListEnumerator.Create(Self);
end;
function TFeldList.GetItem(Index: Integer): TFeld;
begin
Result := TFeld(inherited GetItem(Index));
end;
procedure TFeldList.SetItem(Index: Integer; AObject: TFeld);
begin
inherited SetItem(Index, AObject);
end;
{ TFeldListEnumerator }
constructor TFeldListEnumerator.Create(AList: TFeldList);
begin
FList := AList;
FIndex := -1;
end;
function TFeldListEnumerator.GetCurrent: TFeld;
begin
Result := FList[FIndex];
end;
function TFeldListEnumerator.MoveNext: Boolean;
begin
Result := (FIndex < FList.Count - 1);
if Result then
Inc(FIndex);
end;
Dann einfach TList<TFeld> durch TFeldList ersetzen.