使用循环引用编译 DWScript 单元会出现 ECompileError "Unknown Name"
Compiling DWScript units with circular references gives ECompileError "Unknown Name"
我有两个 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;
在 unit1 的编译过程中,我得到
ECompileError with message 'Unknown Name "unit1.Proc1"'
在 IdwsProgram.Msgs.AsInfo 中添加以下文本:
Syntax Error: Unknown name "unit1.Proc1" [line: 14, column: 9,
file: unit2]
请解释我如何编译这样的循环引用单元。
编辑: 为了使讨论更接近我的要求,我将重新表述问题。为什么DWScript不允许我编译这两个单元?
一种解决方案是将所有内容都放在一个单元中。
另一个是:
unit shared;
interface
procedure Proc1exec;
procedure Proc2exec;
implementation
uses unit1, unit2;
procedure Proc1exec;
begin
unit1.proc1;
end;
procedure Proc2exec;
begin
unit2.proc2;
end;
和
unit unit1;
interface
procedure Proc1;
implementation
procedure Proc1;
begin
// do something useful
end;
end.
和 unit2
.
类似的内容
现在您的代码只需包含:
program Test;
uses
unit1, unit2, shared;
begin
Proc1exec;
Proc2exec;
end.
最后我切换到 PaxCompiler。它可以毫无问题地处理原始 post 中的单位。它也很容易使用,完全满足我的要求。
我有两个 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;
在 unit1 的编译过程中,我得到
ECompileError with message 'Unknown Name "unit1.Proc1"'
在 IdwsProgram.Msgs.AsInfo 中添加以下文本:
Syntax Error: Unknown name "unit1.Proc1" [line: 14, column: 9, file: unit2]
请解释我如何编译这样的循环引用单元。
编辑: 为了使讨论更接近我的要求,我将重新表述问题。为什么DWScript不允许我编译这两个单元?
一种解决方案是将所有内容都放在一个单元中。
另一个是:
unit shared;
interface
procedure Proc1exec;
procedure Proc2exec;
implementation
uses unit1, unit2;
procedure Proc1exec;
begin
unit1.proc1;
end;
procedure Proc2exec;
begin
unit2.proc2;
end;
和
unit unit1;
interface
procedure Proc1;
implementation
procedure Proc1;
begin
// do something useful
end;
end.
和 unit2
.
现在您的代码只需包含:
program Test;
uses
unit1, unit2, shared;
begin
Proc1exec;
Proc2exec;
end.
最后我切换到 PaxCompiler。它可以毫无问题地处理原始 post 中的单位。它也很容易使用,完全满足我的要求。