Solved

interface at different units

Posted on 2004-04-21
6
274 Views
Last Modified: 2010-04-05
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.
0
Comment
Question by:emu10k1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 

Author Comment

by:emu10k1
ID: 10883258
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.
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10883298
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.
 
0
 
LVL 11

Accepted Solution

by:
shaneholmes earned 500 total points
ID: 10883316
I did notice that in your Unit2, you have declared your type under your inplementation section, move it up to interface section

Shane

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.


Should be


unit Unit2;

interface

// 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;


implementation

end.


Shane
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:emu10k1
ID: 10883352
oh ****... I don't believe that the error was that... what attention lack.

Thanks man :)
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10883369
<Smile>

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

SHane
0
 

Author Comment

by:emu10k1
ID: 10883378
:)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to renew a Delphi rad-studio licence? 5 95
Convert a string into a TDateTime 5 81
PHP preg_replace code convert to Delphi 14 98
Tvertscrollbox like a whatsapp layout 5 69
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question