Delphi Web 脚本:执行脚本后访问变量
想象一下这个脚本:
var s = TStrings.Create;
s.Add('Line 1');
s.Add('Line 2');
procedure MyProc;
begin
if s.count = 2 then
// ...
end;
当脚本运行时,它会创建变量“s”。现在我想在脚本完成后调用“MyProc”:
...
Exec := Program.CreateNewExecution;
Exec.BeginProgram;
Exec.RunProgram(0);
if Exec.ProgramState in [psRunning, psRunningStopped] then
begin
Func := Exec.Info.Func['MyProc'];
Func.Call([]);
Exec.EndProgram;
end;
从 MyProc 访问“s”时出现错误。我假设DWS的垃圾收集器已经释放了字符串列表。这是对的吗?我能做点什么让“s”活下去吗?
Imagine this Script:
var s = TStrings.Create;
s.Add('Line 1');
s.Add('Line 2');
procedure MyProc;
begin
if s.count = 2 then
// ...
end;
When the Script runs it creates the variable "s". Now I'd like to call "MyProc" after the script is done:
...
Exec := Program.CreateNewExecution;
Exec.BeginProgram;
Exec.RunProgram(0);
if Exec.ProgramState in [psRunning, psRunningStopped] then
begin
Func := Exec.Info.Func['MyProc'];
Func.Call([]);
Exec.EndProgram;
end;
I get an error accessing "s" from MyProc. I assume that the garbage collector of DWS already freed the stringlist. Is this right? Can I do something to keep "s" alive?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在调用 EndProgram 之前不应清除该变量。
可以解释您的问题的一件事是,如果您的脚本一开始就没有正确编译(检查 Program.Msgs,它应该包含错误)。
That variable should not be cleaned up before the call to EndProgram.
One thing that could explain your issue is if your script didn't compile without errors in the first place (check Program.Msgs, it should then contain the errors).