[英]How to run procedure from another unit?
Well this kind of n00b question but I still can't figure it out. 那么这个n00b问题,但我仍然无法弄清楚。 I have unit
main
with procedure Discard()
in it. 我有单位
main
与程序Discard()
在其中。 Now I have another unit engine
and I want to run from it procedure Discard()
of unit main
. 现在我有另一个单元
engine
,我想从它的单元main
程序Discard()
运行。 I have main in uses
section of engine.pas
. 我有
engine.pas
主要uses
部分。 I tried to call procedure with main.Discard()
but no good. 我试着用
main.Discard()
调用程序,但没有好处。 What am I doing wrong? 我究竟做错了什么?
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: 在“Main”单元中,您在“interface”部分声明Discard:
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. 现在在单元“引擎”中,将“Main”添加到“uses”部分。
uses Main, ...
Thats it, you can call Discard(...)
now. 多数民众赞成,你现在可以打电话给
Discard(...)
。 If there are more than one Discard()
you can explicitely call this Discard()
by using Main.Discard()
. 如果有多个
Discard()
您可以使用Main.Discard()
明确地调用此 Discard()
Main.Discard()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.