Home Compiling DWScript units with circular references gives ECompileError "Unknown Name"
Reply: 2

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

Vlad
1#
Vlad Published in 2017-09-13 11:58:36Z

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?

Rudy Velthuis
2#
Rudy Velthuis Reply to 2017-09-13 12:34:11Z

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.
Vlad
3#
Vlad Reply to 2017-09-16 16:07:12Z

At the end I switched to PaxCompiler. It handles the units from original post without issues. It is also easy to use and covers my requirements completely.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.30281 second(s) , Gzip On .

© 2016 Powered by cudou.com design MATCHINFO