Delphi2010 compiles my TObjectListEnumerator class without error, but DelphiXE3 gives compiler error: E2089: Invalid typecast
What is wrong with this?
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;