How to run procedure from another unit?

青春壹個敷衍的年華 提交于 2019-12-05 05:26:22

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.

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().

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!