[ACCEPTED]-How to run procedure from another unit?-delphi-units

Accepted answer
Score: 11

You need to put the procedure's signature 3 in your interface, like so:

unit main;

interface

procedure Discard();

implementation

procedure Discard();
begin
//do whatever
end;

Other units can 2 only "see" whatever's listed in the interface 1 section.

Score: 9

In unit "Main" you declare Discard in the 4 "interface" section:


unit Main;

interface

uses ...

procedure Discard (...); // only the declaration, not the entire procedure

implementation

... // code

Now in unit "Engine" you 3 add "Main" to the "uses" section.

uses Main, ...

Thats it, you 2 can call Discard(...) now. If there are more than one 1 Discard() you can explicitely call this Discard() by using Main.Discard().

More Related questions