简体   繁体   English

使用循环引用编译DWScript单元会产生ECompileError“未知名称”

[英]Compiling DWScript units with circular references gives ECompileError “Unknown Name”

I have two DWScript unit files: 我有两个DWScript单元文件:

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 在编译unit1时,我得到

ECompileError with message 'Unknown Name "unit1.Proc1"' 消息为“未知名称“ unit1.Proc1”的ECompileError”

with the following text in IdwsProgram.Msgs.AsInfo: 在IdwsProgram.Msgs.AsInfo中包含以下文本:

Syntax Error: Unknown name "unit1.Proc1" [line: 14, column: 9, file: unit2] 语法错误:未知名称“ unit1.Proc1” [行:14,列:9,文件: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? 为什么DWScript不允许我编译这两个单元?

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 . unit2类似。

Now your code only has to include: 现在,您的代码只需包含:

program Test;

uses
  unit1, unit2, shared;

begin
  Proc1exec;
  Proc2exec;
end.

At the end I switched to PaxCompiler. 最后,我切换到PaxCompiler。 It handles the units from original post without issues. 它处理原始帖子中的单元,没有问题。 It is also easy to use and covers my requirements completely. 它也易于使用,完全满足了我的要求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM