Solved

Call Procedure From A Separate Unit

Posted on 2002-04-30
7
334 Views
Last Modified: 2010-04-04
I have two units.  Unit1 holds a procedure called task.
How can I call that procedure from unit2?
0
Comment
Question by:brettawv
7 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6980711
somewhere in unit2

implementation
uses unit1;  //* thats the goal

procedure whatever;
begin
  callproc_in unit1;
end;

meikl ;-)
0
 

Author Comment

by:brettawv
ID: 6980806
Here's what I have.

Unit1:

procedure FillCharCode;
var
  C: Integer;
  F: Integer;
Begin
  F:= 13;
  For C:= 0 to 19 do
    Begin
      With Form1.StringAlignGrid1 Do
        Begin
          Cells[C,0]:= IntToStr(C + 1);
          Cells[C,1]:= DataModule1.AdsQuery10.FieldByName
                       (DataModule1.AdsQuery10.FieldDefs
                       [F].name).AsString;
          F:= F + 1;
        End;
    End;
End;


Unit2:

implementation

uses unit1, dmod1;

{$R *.DFM}

Procedure DoSomething;
Begin
  FillCharCode;
End;

It tells me undeclared identifier 'FillCharCode'.
What am I doing wrong?

Thanks

0
 
LVL 5

Accepted Solution

by:
alanwhincup earned 100 total points
ID: 6981023
Stick this in between interface and implementation in Unit1 and it should work.

procedure FillCharCode;

Cheers,

Alan
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 3

Expert Comment

by:tongalite
ID: 6981030
Hi,
Try adding the variables.
t.
0
 
LVL 5

Expert Comment

by:alanwhincup
ID: 6981032
Unit 1 should then look like:

Unit1;

...

interface

...

procedure FillCharCode;

implementation

...

procedure FillCharCode;
var
 C: Integer;
 F: Integer;
Begin
 F:= 13;
 For C:= 0 to 19 do
   Begin
     With Form1.StringAlignGrid1 Do
       Begin
         Cells[C,0]:= IntToStr(C + 1);
         Cells[C,1]:= DataModule1.AdsQuery10.FieldByName
                      (DataModule1.AdsQuery10.FieldDefs
                      [F].name).AsString;
         F:= F + 1;
       End;
   End;
End;

...

end.
0
 

Author Comment

by:brettawv
ID: 6981056
Thanks, I really appreciate it.
0
 
LVL 4

Expert Comment

by:Greg Rowland
ID: 6981069
alanwhincup is correct, depending on the desired "global" scope of the procedure, You can also do this and declare the procedure normally.


Procedure TForm2.DoSomething;
Begin
 Form1.FillCharCode;
End;

Regards,

Greg
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

839 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