Loading pre compiled script in RemObjects Pascal Script (Delphi)

Hi. I am trying to precompile Pascal Script(s) in Delphi 6. (Using RemObjects Pascal Script for Delphi - 3.0.49.861)

I then want to load them back at a later time in my application so they can be run.

I already have scripts compiling and executing at run time with no issues. I need to precompile for performance reasons.

Now when I try to load the compiled script Delphi excepts with 'Cannot Import VALUE_TEAMCODE.'
Value_TeamCode is a function in my Delphi app that I have already registered with Pascal Script.

Here is what I tried (very rough Psudocode)

Note re code: FPascalScript is a 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 am going about this wrong. I am not sure if it is even possible to load precompiled script.

I searched on RemObjects WebSite Wiki but the Pascal Script help is deleted.

Any help appreciated.

Hello,
You should import this function before using (test with our MyOwnFunction function):

TForm1 = class(TForm)
  ............
  procedure OnExecImport(Sender: TObject; se: TPSExec; x: TPSRuntimeClassImporter);
end;


procedure MyOwnFunction(const Data: string);
begin
  // Do something with Data
  ShowMessage(Data);
end;

procedure TForm1.OnExecImport(Sender: TObject; se: TPSExec; x: TPSRuntimeClassImporter);
begin
  se.RegisterDelphiFunction(@MyOwnFunction, 'MyOwnFunction', cdRegister);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  .................
  FPascalScript.OnExecImport := OnExecImport;
  FPascalScript.SetCompiled(sCompiledScript);
  .................
end;

Cheers. That did the trick.

Only difference in my case is I called RegisterDelphiMethod as my routine was actually off an object instance.