Solved

interface at different units

Posted on 2004-04-21
6
269 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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 remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

914 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

15 Experts available now in Live!

Get 1:1 Help Now