Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

interface at different units

Posted on 2004-04-21
6
Medium Priority
?
277 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 2000 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

721 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