3

我正在尝试使用 Delphi 2010 的 TObjectDictionary 泛型。

我想传递Values该泛型类的属性的枚举器,而编译器似乎不想让我...示例:

  TAttributeStates = class(TInterfacedObject, IAttributeStates)
  private
    FStates: TObjectDictionary<TPatchAttribute, TAttributeState>;

  public

    constructor Create;
    destructor Destroy; override;

    function GetEnumerator: TObjectDictionary<TPatchAttribute, TAttributeState>.TValueEnumerator;

  end;

  implementation

    function TAttributeStates.GetEnumerator: TObjectDictionary<TPatchAttribute, TAttributeState>.TValueEnumerator;
    begin
      result := FStates.Values.GetEnumerator;
    end;

这无法编译并出现错误:

[DCC Error] ChannelStates.pas(249): E2010 Incompatible types: 'TDictionary<Generics.Collections.TObjectDictionary<TKey,TValue>.TKey,Generics.Collections.TObjectDictionary<TKey,TValue>.TValue>.TValueEnumerator' and 'TDictionary<ChannelPatch.TPatchAttribute,ChannelStates.TAttributeState>.TValueEnumerator'

似乎编译器没有正确解析子类型......

有人有想法么?

N@

4

1 回答 1

2

找到了。

function GetEnumerator: TEnumerator<TAttributeState>;


function TAttributeStates.GetEnumerator: TEnumerator<TAttributeState>;
begin
  result := FStates.Values.GetEnumerator;
end;

工作正常。

于 2010-06-25T06:53:38.753 回答