Search code examples
declarationprocedurepascalfreepascallazarus

Call one procedure in another, that was declared before it


I have a situation:

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

procedure CompileBatch();
begin
  //stuff
end;

But that obviously doesn't work, because identifier "CompileBatch" is not yet found in Compile. Are there any workarounds or do I have to rewrite all of the CompileBatch code in Compile? I'm using Free Pascal.


Solution

  • You can do this by declaring your CompileBatch forward, like this:

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