2

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?

1 Answer 1

2

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).

Sign up to request clarification or add additional context in comments.

1 Comment

FWIW your sample code has been added verbatim to the unit tests.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.