How to run procedure from another unit?

Vlad picture Vlad · Sep 11, 2009 · Viewed 13.8k times · Source

Well this kind of n00b question but I still can't figure it out. I have unit main with procedure Discard() in it. Now I have another unit engine and I want to run from it procedure Discard() of unit main. I have main in uses section of engine.pas. I tried to call procedure with main.Discard() but no good. What am I doing wrong?

Answer

Mason Wheeler picture Mason Wheeler · Sep 11, 2009

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.