【问题标题】:E2003 Undeclared identifier: 'ITestInterfataUnit'E2003 未声明的标识符:'ITestInterfataUnit'
【发布时间】:2015-11-30 05:32:53
【问题描述】:

这似乎是一个愚蠢的问题,但我已经为此苦苦挣扎了一段时间。我有两个单位。一个是具有声明接口的单元,另一个是我想实现该接口的表单。代码:

unit ITestInterfata;

interface


implementation

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

    procedure Intrare(s : string);
  end;

end.

主窗体单元:

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.

如果我使用 CTRL+单击ITestInterfataUnit,它会将我带到正确位置的正确单元。我在这里看到过这样的问题,并且我已经尝试了我在那里看到的所有解决方案。

  • 再次创建项目
  • 关闭并打开 Delphi IDE
  • 检查接口单元是否在uses主窗体中声明
  • 确保我为该单元命名,这样就不会有其他同名的 .dcu 文件。

【问题讨论】:

    标签: delphi


    【解决方案1】:

    只有在一个单元的接口部分定义的符号被导出,因此在其他单元中可见。您在实现部分定义了符号ITestInterfataUnit,因此ITestInterfataUnit 在其他单元中不可见。

    documentation 说:

    接口部分声明了客户端可用的常量、类型、变量、过程和函数。也就是说,对于希望使用本单元元素的其他单元或程序。这些实体被称为公共实体,因为其他单元中的代码可以访问它们,就像它们在单元本身中声明一样。

    ....

    除了公共过程和函数的定义之外,实现部分可以声明单元私有的常量、类型(包括类)、变量、过程和函数。也就是说,与接口部分不同,在实现部分中声明的实体对其他单元是不可访问的。

    您必须在接口部分定义ITestInterfataUnit。

    unit ITestInterfata;
    
    interface
    
    type
      ITestInterfataUnit = interface
        ['{A0CD69F8-C919-4D2D-9922-A7A38A6C841C}']
    
        procedure Intrare(s : string);
      end;
    
    implementation
    
    end.
    

    【讨论】:

    • 你刚刚救了我很多神经。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2012-06-27
    • 1970-01-01
    • 2015-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-30
    相关资源
    最近更新 更多