How to run procedure from another unit?
15,021
Solution 1
You need to put the procedure's signature in your interface, like so:
unit main;
interface
procedure Discard();
implementation
procedure Discard();
begin
//do whatever
end;
Other units can only "see" whatever's listed in the interface section.
Solution 2
In unit "Main" you declare Discard in the "interface" section:
unit Main;
interface
uses ...
procedure Discard (...); // only the declaration, not the entire procedure
implementation
... // code
Now in unit "Engine" you add "Main" to the "uses" section.
uses Main, ...
Thats it, you can call Discard(...)
now. If there are more than one Discard()
you can explicitely call this Discard()
by using Main.Discard()
.
Author by
Vlad
Updated on June 09, 2022Comments
-
Vlad almost 2 years
Well this kind of n00b question but I still can't figure it out. I have unit
main
with procedureDiscard()
in it. Now I have another unitengine
and I want to run from it procedureDiscard()
of unitmain
. I have main inuses
section ofengine.pas
. I tried to call procedure withmain.Discard()
but no good. What am I doing wrong?