Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 341
  • Last Modified:

Call Procedure From A Separate Unit

I have two units.  Unit1 holds a procedure called task.
How can I call that procedure from unit2?
0
brettawv
Asked:
brettawv
1 Solution
 
kretzschmarCommented:
somewhere in unit2

implementation
uses unit1;  //* thats the goal

procedure whatever;
begin
  callproc_in unit1;
end;

meikl ;-)
0
 
brettawvAuthor Commented:
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
 
alanwhincupCommented:
Stick this in between interface and implementation in Unit1 and it should work.

procedure FillCharCode;

Cheers,

Alan
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
tongaliteCommented:
Hi,
Try adding the variables.
t.
0
 
alanwhincupCommented:
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
 
brettawvAuthor Commented:
Thanks, I really appreciate it.
0
 
Greg RowlandSoftware Designer, SysDBA, WebMaster OwnerCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Tackle projects and never again get stuck behind a technical roadblock.
Join Now