传递对 TObjectDictionary.TValueEnumerator 的引用
我正在尝试使用 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'
看起来编译器没有正确解析子类型...
有人有什么想法吗?
氮@
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@
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
找到了。
工作正常。
Found it.
Works fine.