CiucaS
CiucaS

Reputation: 2128

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. I've seen a problem like that being discuss here and I've tried everything I saw as a solution there.

Upvotes: 1

Views: 598

Answers (1)

David Heffernan
David Heffernan

Reputation: 613242

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.

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.

unit ITestInterfata;

interface

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

    procedure Intrare(s : string);
  end;

implementation

end.

Upvotes: 5

Related Questions