在另一个过程中调用一个过程,在它之前声明

Gre*_*orn 1 pascal freepascal procedure declaration lazarus

我有一个情况:

procedure Compile();
begin
  //stuff
  CompileBatch();
end;

procedure CompileBatch();
begin
  //stuff
end;
Run Code Online (Sandbox Code Playgroud)

但这显然不起作用,因为在 Compile 中还没有找到标识符“CompileBatch”。是否有任何解决方法,或者我是否必须在 Compile 中重写所有 CompileBatch 代码?我正在使用 Free Pascal。

Mar*_*ynA 5

您可以通过声明 CompileBatch 来做到这一点forward,如下所示:

procedure CompileBatch(); forward;

procedure Compile();
begin
  //stuff
  CompileBatch();
end;

procedure CompileBatch();
begin
  //stuff
end;
Run Code Online (Sandbox Code Playgroud)