Using script functions as Delphi event handler

<< Click to Display Table of Contents >>

Navigation:  Using Delphi classes and functions >

Using script functions as Delphi event handler

Script functions can be used as Delphi components event handler. Currently library supports only events of following types:

TNotifyEvent

TCloseQuery

TMouseDown

TMouseMove

TMouseWheel

 

To use script function as event handler simply assign a function to event property in a script code:

 
procedure TestEvent(Sender: TObject);
begin
  ShowMessage(Sender.Name);
end;
 
Form.OnDblClick := TestEvent;
 

Setting event handler from Delphi code

 

To set script function as event handler use TScriptFunc.AsNotifyEvent property.

Example:

 

 Form1.OnDblClick := Script.CreateAnonymousFunction('MessageDlg(''Test'', 

  mtWarning, [mbYes, mbNo, mbCancel], 0)').AsNotifyEvent;

 

Using existing script function:

 

 Form1.OnDblClick := Script.FindFunction('MyEventHandler').AsNotifyEvent;