开发者

Passing a reference to a TObjectDictionary<TKey, TValue>.TValueEnumerator

开发者 https://www.devze.com 2023-01-05 04:15 出处:网络
I am trying to use Delphi 2010\'s TObjectDictionary generic. I would like to pass an enumerator of the Values property of that generic class, and the compiler doesn\'t seem to want to let me... Examp

I am trying to use Delphi 2010's TObjectDictionary generic.

I would like to pass an enumerator of the Values property of that generic class, and the compiler doesn't seem to want to let me... Example:

  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.G开发者_JS百科etEnumerator: TObjectDictionary<TPatchAttribute, TAttributeState>.TValueEnumerator;
    begin
      result := FStates.Values.GetEnumerator;
    end;

This fails to compile with the error:

[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'

It seems that the compiler isn't resolving the sub-type properly...

Anyone have any ideas?

N@


Found it.

function GetEnumerator: TEnumerator<TAttributeState>;


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

Works fine.

0

精彩评论

暂无评论...
验证码 换一张
取 消