【发布时间】:2012-05-15 20:51:56
【问题描述】:
我正在尝试使用 dwscript 创建一个模态表单。我用 ExposeRtti 注册表单,然后执行脚本,但它在 Script.Compile 期间因“堆栈溢出”而失败。有没有人有这个错误的解决方案。
我当然希望我不必像使用 remobjects PascalScript 那样手动注册所有 TForm 属性和函数,这会让我们在这个时代变得丑陋,想避免这种情况..
dwscript 可以做到这一点,还是表单只是超出了 dwscript 的范围(现阶段?)?
procedure TMainForm.Button1Click(Sender: TObject);
var AdwsProgramExecution: IdwsProgramExecution;
ADelphiWebScript: TDelphiWebScript;
AdwsProgram: IdwsProgram;
AdwsUnit: TdwsUnit;
begin
AdwsUnit := TdwsUnit.Create(nil);
ADelphiWebScript := TDelphiWebScript.Create(nil);
try
AdwsUnit.UnitName := 'ShowModalTest';
AdwsUnit.Script := ADelphiWebScript;
AdwsUnit.ExposeRTTI(TypeInfo(TObject)); //Otherwise GetOnAlignInsertBefore error when 'compiling'
AdwsUnit.ExposeRTTI(TypeInfo(TForm)); //Want t ocreate a form
AdwsProgram := ADelphiWebScript.Compile('procedure TestShowModal; begin TForm.Create(nil).ShowModal; end; end.'); //Stack overflow
if AdwsProgram.Msgs.Count = 0 then
begin
AdwsProgramExecution := AdwsProgram.Execute;
MEResult.Lines.Text := AdwsProgramExecution.Result.ToString;
end
else
MEResult.Lines.Text := AdwsProgram.Msgs.AsInfo;
finally
ADelphiWebScript.Free;
AdwsUnit.Free;
end;
end;
【问题讨论】:
-
不确定是否可以使用 TForm,它具有自身需要在 TForm 类之前公开的属性,为什么不简单地在 TdwsUnit 的类集合中创建一个更轻量级的 TForm 版本?
-
错误实际上是在编译期间发生的,还是在它之前的
ExposeRTTI调用期间发生的?这似乎更有可能。 -
SO 与 TForm 无关。如果您只从 TObject 执行 ExposeRTTI 并且有一个空脚本,甚至会发生这种情况。
-
如果您需要大约 1000 个应用程序类,更好的方法可能是使用 RTTI 环境,这样可以避免解析 1000 个 RTTI 数据结构。
-
@Eric;你有一些快速的指示或例子让我走上 RTTI 路线吗?到目前为止我发现的唯一东西是 TRTTIEnvironment 但我(和谷歌)不知道如何让它工作。
标签: delphi stack-overflow dwscript