Calling a specific function from pascal script

Hi,

We have a desktop app and we are using Pascal Script for different events, for example on opening a menu, opening a record, record change, field change, etc. For all this events we have one or more pascal scripts, which are executed on the event.
If we make from all this scripts one script, which will have specific procedures for all the events, what is the most better way to call the procedures (from delphi code) when the event is triggered?
Now we are caching the compiled scripts and executing them when the event occurs.

Thank you and best regards.

Hi,

You can use your current implementation.

in console samples we use this way:

const
  Script = 'begin MyOwnFunction(); end.';
begin
  ExecuteScript(Script);
end.

I think I wasn’t very clear. Bellow is a test script, which is doing nothing

procedure OnMyOpenMenu(Sender: TObject);
begin
  ShowMessage('Event: open menu');
end;

procedure OnMyRecordChange(Sender: TObject);
begin
  ShowMessage('Event: on record change');
end;

procedure OnMyFieldChange(Sender: TObject);
begin
  ShowMessage('Event: on record change');
end;

begin
end.

This script is compiled and executed once and cached in memory, without freeing the runtime and classimporter components.

When an event occurs in our application (the user opens a new menu), than we want to call OnMyOpenMenu event from the script (runtime).

Hi,

You can use another pascal script like

uses myunit;
begin
  OnMyOpenMenu(nil);
end.

or

{$I myunit.inc}
begin
  OnMyOpenMenu(nil);
end.

delphi - PascalScript including other script per uses or include command - Stack Overflow describes required steps.