Solved

Call Procedure From A Separate Unit

Posted on 2002-04-30
7
332 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
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.

 
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:SurferJoe
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

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

Suggested Solutions

Title # Comments Views Activity
Delphi 2010 Export to pdf 2 287
indy tidtcpclient threading issue 8 63
Create Database on Android via Delphi dbExpress 3 80
URL for downloading Google Chrome for Win XP 2 122
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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…

895 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

12 Experts available now in Live!

Get 1:1 Help Now