# Calling a specific function from pascal script

**URL:** https://talk.remobjects.com/t/calling-a-specific-function-from-pascal-script/30877
**Category:** Pascal Script
**Created:** [October 2, 2024, 6:04am UTC](https://talk.remobjects.com/t/calling-a-specific-function-from-pascal-script/30877 "2024-10-02T06:04:44Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![\_Koncz\_Timea](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/_/ecc23a/32.png) [@\_Koncz\_Timea](https://talk.remobjects.com/u/_Koncz_Timea)
#### Post date: [October 2, 2024, 6:04am UTC](https://talk.remobjects.com/t/calling-a-specific-function-from-pascal-script/30877/1 "2024-10-02T06:04:45Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [October 2, 2024, 6:27am UTC](https://talk.remobjects.com/t/calling-a-specific-function-from-pascal-script/30877/2 "2024-10-02T06:27:57Z")

</div>

Hi,

You can use your current implementation.

in console samples we use this way:

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

```

---

<div class="post-metadata">

### Author: ![\_Koncz\_Timea](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/_/ecc23a/32.png) [@\_Koncz\_Timea](https://talk.remobjects.com/u/_Koncz_Timea)
#### Post date: [October 2, 2024, 7:19am UTC](https://talk.remobjects.com/t/calling-a-specific-function-from-pascal-script/30877/3 "2024-10-02T07:19:23Z")

</div>

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

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

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [October 3, 2024, 8:52am UTC](https://talk.remobjects.com/t/calling-a-specific-function-from-pascal-script/30877/4 "2024-10-03T08:52:08Z")

</div>

Hi,

You can use another pascal script like

```auto
uses myunit;
begin
  OnMyOpenMenu(nil);
end.

```

or

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

```

[delphi - PascalScript including other script per uses or include command - Stack Overflow](https://stackoverflow.com/questions/6135389/pascalscript-including-other-script-per-uses-or-include-command) describes required steps.
