2010-06-25 6 views
3

J'essaie d'utiliser le générique TObjectDictionary de Delphi 2010.Passage d'une référence à un TObjectDictionary <TKey, TValue> .TValueEnumerator

Je voudrais passer un recenseur de la propriété Values de cette classe générique, et le compilateur ne semble pas vouloir me laisser ... Exemple:

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; 

Cela ne peut pas compiler avec le erreur:

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

Il semble que le compilateur ne résout pas le sous-type bien ...

Quelqu'un a des idées?

N @

Répondre

2

Trouvé.

function GetEnumerator: TEnumerator<TAttributeState>; 


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

Fonctionne bien.

Questions connexes