Solved

Call Procedure From A Separate Unit

Posted on 2002-04-30
7
336 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
[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
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
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!

 
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

691 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