简体   繁体   English

Delphi - 使用来自另一个单元的接口

[英]Delphi - Using interfaces from another unit

I am constantly getting the: Undeclared identifier for an interface type I have defined in another unit.我不断收到:我在另一个单元中定义的接口类型的未声明标识符。 Here is what I have:这是我所拥有的:

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;

At FSymbolDrawer I get the complier error.在 FSymbolDrawer 我得到编译器错误。

Of course I have the uses Drawers;当然我有抽屉的用途; in the unit where TField is defined.在定义 TField 的单位中。

What's this about?这是怎么回事?

Thank you谢谢

In the unit Drawers the type declaration of IDrawer has to be in the interface part of the unit.在单元Drawers中, IDrawer的类型声明必须在单元的接口部分。 You have inserted it in the implementation part where it is only visible for in-unit declarations.您已将它插入到仅对单元内声明可见的实现部分。

Here is the code:这是代码:

unit Drawers;

interface

type

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

implementation

end.

Which uses clause do you add Drawers to?您将Drawers添加到哪个 uses 子句? It has to be in the interface uses clause (above the definition of TField that uses it).它必须在interface uses 子句中(在使用它的TField的定义之上)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM