我正在尝试使用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 - [
答案 0 :(得分:2)
找到它。
function GetEnumerator: TEnumerator<TAttributeState>;
function TAttributeStates.GetEnumerator: TEnumerator<TAttributeState>;
begin
result := FStates.Values.GetEnumerator;
end;
工作正常。