0

Delphi2010 は TObjectListEnumerator クラスをエラーなしでコンパイルしますが、DelphiXE3 はコンパイラ エラーを返します: E2089: 無効な型キャスト

これの何が問題なのですか?

    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;
4

1 に答える 1