简体   繁体   English

E2003 未声明的标识符:'ITestInterfataUnit'

[英]E2003 Undeclared identifier: 'ITestInterfataUnit'

It looks like a silly question, but I've been struggling with it for some time.这看起来是一个愚蠢的问题,但我已经为此苦苦挣扎了一段时间。 I have two units.我有两个单位。 One is a unit with an declared interface and the other one is a Form that I would like to implement that interface.一个是带有声明接口的单元,另一个是我想实现该接口的表单。 Code:代码:

unit ITestInterfata;

interface


implementation

 type
  ITestInterfataUnit = interface
    ['{A0CD69F8-C919-4D2D-9922-A7A38A6C841C}']

    procedure Intrare(s : string);
  end;

end.

Main form unit:主要形式单位:

unit frameTestInterfata;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, ITestInterfata;



type
  TformaTestInterfata = class(TForm, ITestInterfataUnit)
    Button1: TButton;
  private
    { Private declarations }
  public
    { Public declarations }
    procedure Intrare(s: string);
  end;

var
  formaTestInterfata: TformaTestInterfata;

implementation

{$R *.dfm}


{ TformaTestInterfata }

procedure TformaTestInterfata.Intrare(s: string);
begin
  ShowMessage('asdf');
end;

end.

If I use the CTRL+Click on ITestInterfataUnit it takes me to the right unit in the right place.如果我在ITestInterfataUnit上使用 CTRL+单击,它会将我带到正确位置的正确单元。 I've seen a problem like that being discuss here and I've tried everything I saw as a solution there.我已经看到这里讨论过这样的问题,我已经尝试了所有我认为的解决方案。

  • create the project again再次创建项目
  • close and open the Delphi IDE关闭和打开 Delphi IDE
  • check if the interface unit is declare in uses in main form检查接口单元是否在主窗体中声明uses
  • made sure that I gave a name to the unit so there would be no other .dcu's with the same name.确保我为该单元命名,因此不会有其他同名的 .dcu。

Only symbols defined in the interface section of a unit are exported and so visible in other units.只有在单元的接口部分中定义的符号才会被导出并在其他单元中可见。 You defined the symbol ITestInterfataUnit in the implementation section and so ITestInterfataUnit is not visible in other units.您在实现部分定义了符号ITestInterfataUnit ,因此ITestInterfataUnit在其他单元中不可见。

The documentation says: 文档说:

The interface section declares constants, types, variables, procedures, and functions that are available to clients.接口部分声明了客户端可用的常量、类型、变量、过程和函数。 That is, to other units or programs that wish to use elements from this unit.也就是说,对于希望使用该单元中的元素的其他单元或程序。 These entities are called public because code in other units can access them as if they were declared in the unit itself.这些实体被称为公共实体,因为其他单元中的代码可以访问它们,就像它们在单元本身中声明一样。

.... ....

In addition to definitions of public procedures and functions, the implementation section can declare constants, types (including classes), variables, procedures, and functions that are private to the unit.除了公共过程和函数的定义之外,实现部分还可以声明单元私有的常量、类型(包括类)、变量、过程和函数。 That is, unlike the interface section, entities declared in the implementation section are inaccessible to other units.也就是说,与接口部分不同,其他单元无法访问在实现部分中声明的实体。

You must define ITestInterfataUnit in the interface section.您必须在接口部分定义ITestInterfataUnit

unit ITestInterfata;

interface

type
  ITestInterfataUnit = interface
    ['{A0CD69F8-C919-4D2D-9922-A7A38A6C841C}']

    procedure Intrare(s : string);
  end;

implementation

end.

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

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