Board index » delphi » procedure question

procedure question

Hi,

I created 2 forms and 2 units.  I created a procedure (user defined) in
unit 1 and I use it in unit1.  My problem can I call the same procedure
that is located in unit 1 from unit 2?  Any help will be greatly
appreciated.

thanks
tony

 

Re:procedure question


Declare de unit2 in the uses clause of the unit1. As simple as that/

On 18 Mar 1997 14:54:50 GMT, ttsanga...@aol.com (TTsangarak) wrote:

Quote
>Hi,

>I created 2 forms and 2 units.  I created a procedure (user defined) in
>unit 1 and I use it in unit1.  My problem can I call the same procedure
>that is located in unit 1 from unit 2?  Any help will be greatly
>appreciated.

>thanks
>tony

Re:procedure question


Quote
TTsangarak wrote:

> Hi,

> I created 2 forms and 2 units.  I created a procedure (user defined) in
> unit 1 and I use it in unit1.  My problem can I call the same procedure
> that is located in unit 1 from unit 2?  Any help will be greatly
> appreciated.

> thanks
> tony

Ddd 'Unit1' into uses clause of Unit2.

In Unit1 put declaration of the procedure between interface and
implementation, e.g.

--------------------------------
unit Unit1;

interface

uses Dialogs;

procedure myproc;

implementation

procedure myproc;
begin
  ShowMessage('here we go');
end;

end.
-------------------------------
unit Unit2;

interface

uses Unit1, ..., ...;
...
...
implementation

procedure TForm1.Button1Click(Sender: TObject);
begin
  myproc;
end;

end.

Re:procedure question


Quote
ttsanga...@aol.com (TTsangarak) writes:

> Hi,

> I created 2 forms and 2 units.  I created a procedure (user defined) in
> unit 1 and I use it in unit1.  My problem can I call the same procedure
> that is located in unit 1 from unit 2?  Any help will be greatly
> appreciated.

If you give a formal declaration for your procedure in the
INTERFACE part of unit1, and add unit1 to the USES clause of unit2,
preferably in the IMPLEMENTATION part, although there's nothing except
the principle of information-hiding and the possibility of circular
references (which Delphi can't handle) to prevent you from putting it
in the INTERFACE part <pause for breath>, then yes, you can do that,
no problem
--
-----------------------------------
Matt Francomb, Setanta Software Ltd
http://www.demon.co.uk/setanta
-----------------------------------

Other Threads