3

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.GetEnumerator: 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@

1 Answer 1

2

Found it.

function GetEnumerator: TEnumerator<TAttributeState>;


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

Works fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.