Sea*_*ess 6 delphi procedure forward-declaration
如何在Delphi中进行程序的前向声明并使其在其他地方实现?我想做这样的C代码,但是在Delphi中:
void FooBar();
void FooBar()
{
// Do something
}
Run Code Online (Sandbox Code Playgroud)
Mas*_*ler 18
您可以使用该forward指令执行此操作,如下所示:
procedure FooBar(); forward;
...
//later on
procedure FooBar()
begin
// Do something
end;
Run Code Online (Sandbox Code Playgroud)
只有当您将其声明为内部函数时,才需要这样做.(即已经在implementation你单位的部分内.)任何被宣称为一个类的方法,或在interface单元的部分中,被自动理解为向前声明的.
这是通过单元的接口/实现部分来实现它的一种方式.
Unit YourUnit;
Interface
procedure FooBar(); // procedure declaration
Implementation
// Here you can reference the procedure FooBar()
procedure FooBar();
begin
// Implement your procedure here
end;
Run Code Online (Sandbox Code Playgroud)
您还应该查看有关forward declarations提及其他选项的文档,例如@MasonWheeler回答.