delphidwscript

Compiling DWScript units with circular references gives ECompileError "Unknown Name"


I have two DWScript unit files:

unit unit1;                    | unit unit2;
                               | 
interface                      | interface
                               | 
procedure Proc1exec;           | procedure Proc2exec;
procedure Proc1;               | procedure Proc2;
                               | 
implementation                 | implementation
                               | 
uses unit2;                    | uses unit1;
                               | 
procedure Proc1exec;           | procedure Proc2exec;
begin                          | begin
  unit2.Proc2;                 |   unit1.Proc1;
end;                           | end;
                               | 
procedure Proc1;               | procedure Proc2;
begin                          | begin  
end;                           | end;

During compilation of unit1 I get

ECompileError with message 'Unknown Name "unit1.Proc1"'

with the following text in IdwsProgram.Msgs.AsInfo:

Syntax Error: Unknown name "unit1.Proc1" [line: 14, column: 9, file: unit2]

Kindly explain how could I compile such circular referenced units.

Edit: In order to make the discussion closer to my requirements, I'll reformulate the question. Why DWScript does not allow me to compile these two units?


Solution

  • One solution is to put everything in one unit.

    Another one is:

    unit shared;
    
    interface
    
    procedure Proc1exec;
    procedure Proc2exec;
    
    implementation
    
    uses unit1, unit2;
    
    procedure Proc1exec;
    begin
      unit1.proc1;
    end;
    
    procedure Proc2exec;
    begin
      unit2.proc2;
    end;
    

    and

    unit unit1;
    
    interface
    
    procedure Proc1;
    
    implementation
    
    procedure Proc1;
    begin
      // do something useful
    end;
    
    end.
    

    And something similar for unit2.

    Now your code only has to include:

    program Test;
    
    uses
      unit1, unit2, shared;
    
    begin
      Proc1exec;
      Proc2exec;
    end.