Loading a precompiled script in RemObjects Pascal script (Delphi)

I am trying to load pre-executed RemObjects Pascal Script into Delphi at runtime. However, when I try to download it, Delphi throws out "Unable to import VALUE_TEAMCODE." Value_TeamCode is a function in my Delphi application that I have already registered with Pascal Script.

That's what I'm doing. Coarse pseudo code below - the actual code is split into several files. In addition, the call to SetCompiled below occurs much later in the application when you need to execute Script.

Note regarding code: FPascalScript is TPSScriptDebugger

 ... //Register custom functions with Pascal Script FuncsRegister; //Load script FPascalScript.Script.AddStrings(AContent); //Compile script FPascalScript.Compile; //Get compiled script FPascalScript.GetCompiled(sCompiledScript) //Try and set script back in - ERROR Here 'Cannot Import VALUE_TEAMCODE' FPascalScript.PascalScript.Debugger.SetCompiled(sCompiledScript); ... 

Maybe I'm going to do it wrong. I'm not sure if you can even download pre-compiled Script.

I searched the RemObjects WebSite Wiki, but the Pascal Script help has been removed. I also searched for various topics here in StackOverflow, but none of them are related to this issue.

One more remark. I already have scripts that compile and execute at runtime without any problems. I need to precompile for performance reasons.

Any help was appreciated.

Update:

The current job is to have one Script engine for Script in my system. Then these engines remain in memory after preliminary compilation. This removes the 30 ms per script compilation overhead that I otherwise had. It also uses a little more memory, but not enough to be a problem.

I would prefer to use only one Script engine. (Therefore, you must load the precompiled script)

+8
delphi pascal pascalscript
source share
2 answers

Thanks to the answer on the RemObject Connect beta forum, I have a solution. (For posts, see http://connect.remobjects.com/discussion/comment/13540#Comment_13540 )

Thanks for the poster vovanl.

I had to import my functions through the OnExecImport event as follows:

 ... FPascalScript.OnExecImport := OnExecImport; FPascalScript.SetCompiled(sCompiledScript); ... TMyClass.OnExecImport(Sender: TObject; se: TPSExec; x: TPSRuntimeClassImporter); begin se.RegisterDelphiFunction(@Value_TeamCode, 'Value_TeamCode', cdRegister); end; ... 

Appears SetCompiled clears all existing registrations and therefore you MUST connect to OnExecImport to re-register functions, procedures, methods, etc.

Note that loading a pre-compiled script appears (i.e. changing one script for another), it seems to add extra extra overhead. I found that my initial work was actually about 6 times faster.

+1
source share

Instead of how to do it, I'm going to meet why?

Compiled scripts are more likely to be associated with a version, possibly even with a platform / target binding - and they usually build fast enough so you never notice a point in time. Are you really using scripts intensively enough to make compilation time a problem?

Sometimes the best answer is: "Do you really need to do this at all?"

0
source share

All Articles