Solved

interface at different units

Posted on 2004-04-21
6
268 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
  • 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now