这看起来像一个愚蠢的问题,但我一直在努力解决它.我有两个单位.一个是具有声明接口的单元,另一个是我想要实现该接口的Form.码:
unit ITestInterfata;
interface
implementation
type
ITestInterfataUnit = interface
['{A0CD69F8-C919-4D2D-9922-A7A38A6C841C}']
procedure Intrare(s : string);
end;
end.
Run Code Online (Sandbox Code Playgroud)
主要单位:
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.
Run Code Online (Sandbox Code Playgroud)
如果我使用CTRL +点击ITestInterfataUnit它会把我带到正确位置的正确单位.我已经看到了像这样讨论的问题,我已经尝试了所有我看到的解决方案.
uses以主窗体声明仅导出单元的接口部分中定义的符号,因此在其他单元中可见.您ITestInterfataUnit在实现部分中定义了符号,因此ITestInterfataUnit在其他单元中不可见.
该文件说:
在接口部分声明是提供给客户的常量,类型,变量,过程和函数.也就是说,希望使用本单元中的元素的其他单位或程序.这些实体被称为public,因为其他单元中的代码可以访问它们,就像它们在单元本身中声明一样.
....
除了公共过程和函数的定义之外,实现部分还可以声明对单元私有的常量,类型(包括类),变量,过程和函数.也就是说,与接口部分不同,实现部分中声明的实体对于其他单元是不可访问的.
您必须ITestInterfataUnit在界面部分中定义.
unit ITestInterfata;
interface
type
ITestInterfataUnit = interface
['{A0CD69F8-C919-4D2D-9922-A7A38A6C841C}']
procedure Intrare(s : string);
end;
implementation
end.
Run Code Online (Sandbox Code Playgroud)