Delphi2010 编译我的 TObjectListEnumerator 类没有错误,但 DelphiXE3 给出编译器错误:E2089: Invalid typecast
这有什么问题?
TObjectListEnumerator<T> = class
private
fList : TObjectList;
fIndex : integer;
fMaxIndex : integer;
function GetCurrent : T;
public
constructor Create(List: TObjectList);
function MoveNext : Boolean;
property Current : T read GetCurrent;
end;
constructor TObjectListEnumerator<T>.Create(List: TObjectList);
begin
inherited Create;
fList := List;
fIndex := -1;
fMaxIndex := fList.Count-1;
end;
function TObjectListEnumerator<T>.MoveNext: Boolean;
begin
Inc(fIndex);
Result := not(fIndex > fMaxIndex);
end;
function TObjectListEnumerator<T>.GetCurrent: T;
begin
Result := T(fList[fIndex]); // <-- E2089: Invalid typecast
end;