传递对 TObjectDictionary.TValueEnumerator 的引用

发布于 2024-09-07 03:49:47 字数 1102 浏览 0 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

魔法少女 2024-09-14 03:49:47

找到了。

function GetEnumerator: TEnumerator<TAttributeState>;


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

工作正常。

Found it.

function GetEnumerator: TEnumerator<TAttributeState>;


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

Works fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文