【问题标题】:Delphi - Using interfaces from another unitDelphi - 使用来自另一个单元的接口
【发布时间】:2011-05-04 19:46:06
【问题描述】:

我经常收到:我在另一个单元中定义的接口类型的未声明标识符。 这是我所拥有的:

unit Drawers;

interface

implementation

type

  IDrawer = interface
  ['{070B4742-89C6-4A69-80E2-9441F170F876}']
    procedure Draw();
  end;

end.

unit Field;

interface

uses
  Graphics, Classes, Drawers;

TField = class(TInterfacedObject, IField)
private
  FSymbolDrawer: IDrawer;

在 FSymbolDrawer 我收到编译器错误。

当然我有抽屉的用途;在定义 TField 的单元中。

这是怎么回事?

谢谢

【问题讨论】:

    标签: delphi


    【解决方案1】:

    在单元Drawers 中,IDrawer 的类型声明必须在单元的接口部分。您已将它插入到仅对单元内声明可见的实现部分中。

    代码如下:

    unit Drawers;
    
    interface
    
    type
    
      IDrawer = interface
      ['{070B4742-89C6-4A69-80E2-9441F170F876}']
        procedure Draw();
      end;
    
    implementation
    
    end.
    

    【讨论】:

    • 我不敢相信我忽略了这一点。我现在应该去睡觉了。谢谢。
    • @elector:晚安!睡个好觉;-)
    • 好收获!我完全错过了——我想我只是自动将其读为interface,因为它跟随unit。 +1
    【解决方案2】:

    您将Drawers 添加到哪个uses 子句?它必须在 interface 使用子句中(在使用它的 TField 的定义之上)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-03
      • 2022-01-23
      • 2013-11-27
      • 1970-01-01
      • 2023-03-25
      • 1970-01-01
      相关资源
      最近更新 更多