Link to home
Start Free TrialLog in
Avatar of emu10k1
emu10k1

asked on

interface at different units

Hi, I create a unit and put this code there:

unit Unit2;

interface

implementation
// the interface code
type
  IAgendas = interface
    ['{2CFE9F89-A88D-4179-9429-2340CC67435B}']
    function getNome(): String;
    procedure setNome(Nome: String);
    function getFone(): String;
    procedure setFone(Fone: String);
  end;

end.

----------------------------------
now I create another unit to use the interface

unit Unit3;

interface

uses Unit2; // to use the interface declared at unit2

implementation

type
  TAgenda = class (TInterfacedObject, IAgendas)
    public
      function getNome(): String;
      procedure setNome(Nome: String);
      function getFone(): String;
      procedure setFone(Fone: String);
    private
      Nome: String;
      Fone: String;
  end;

function TAgenda.getNome(): String;
begin
  Result := Self.Nome;
end;

procedure TAgenda.setNome(Nome: String);
begin
  Self.Nome := Nome;
end;

function TAgenda.getFone(): String;
begin
  Result := Self.Fone;
end;

procedure TAgenda.setFone(Fone: String);
begin
  Self.Fone := Fone;
end;

end.


but it shows an error when I try to compile at Unit3: 'Undeclared identifier: 'IAgendas'

Why it shows me that error? I put the Unit at uses clause and it didn't recognize IAgendas.

Please help me with that, Thanks.
Avatar of emu10k1
emu10k1

ASKER

I would like use at different units, because if I put it at same unit it works fine.... but if I try to use the interface at another unit it shows me the same error.
hmmmmm, doesn't give me an error

SHane



___________________________________________________________________

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm1 = class(TForm)
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses Unit2;

{$R *.dfm}

end.

___________________________________________________________________

unit Unit2;

interface
 type
 IAgendas = interface
    ['{2CFE9F89-A88D-4179-9429-2340CC67435B}']
    function getNome(): String;
    procedure setNome(Nome: String);
    function getFone(): String;
    procedure setFone(Fone: String);
  end;


implementation

end.
 
___________________________________________________________________


unit Unit3;

interface

uses Unit2;

type
  TAgenda = class (TInterfacedObject, IAgendas)
    public
      function getNome(): String;
      procedure setNome(Nome: String);
      function getFone(): String;
      procedure setFone(Fone: String);
    private
      Nome: String;
      Fone: String;
  end;

implementation

function TAgenda.getNome(): String;
begin
  Result := Self.Nome;
end;

procedure TAgenda.setNome(Nome: String);
begin
  Self.Nome := Nome;
end;

function TAgenda.getFone(): String;
begin
  Result := Self.Fone;
end;

procedure TAgenda.setFone(Fone: String);
begin
  Self.Fone := Fone;
end;

end.


end.
 
ASKER CERTIFIED SOLUTION
Avatar of shaneholmes
shaneholmes

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of emu10k1

ASKER

oh ****... I don't believe that the error was that... what attention lack.

Thanks man :)
<Smile>

I do that all the time - You can stare at the code for hours.....

SHane
Avatar of emu10k1

ASKER

:)