Ekas Software Windows Script Host Control for Delphi Help
Script procedures as event handlers
Quick start: common questions
Script procedures can be set as event handlers for Delphi objects very easy. There is the set of routing methods in TekWSHControl class to set script procedures as event handlers by one line of code. They have the same procedure types as corresponding events (TxxxEvent) and same parameter sets. Here is the list of events having predefined routers in the script control (and you can add other events if needed having registered version with source codes or writing custom descendants of TekWSHControl):

(* For TControl events *)

OnClick

OnDblClick

OnMouseDown

OnMouseMove

OnMouseUp

OnResize

OnCanResize

OnConstrainedResize

OnContextPopup

(* For TWinControl events *)

OnEnter

OnExit

OnKeyDown

OnKeyUp

OnKeyPress

OnMouseWheelDown

OnMouseWheelUp

OnMouseWheel

(* For TTimer events *)

OnTimer

(* For TForm events *)

OnActivate

OnCreate

OnDeactivate

OnDestroy

OnHide

OnPaint

OnShow

OnClose

OnCloseQuery

(* Other events *)

OnChange(Sender: TObject)

OnChanging(Sender: TObject)

OnExecute(Sender: TObject)

Accordable event routers have hames xxxHandler (where xxx is the name of event). For example, 'OnClick' event router has name 'OnClickHandler'.

And when you write in Delphi:

Panel1.OnClick:= ekWSHControl.OnClickHandler,

the script procedure Panel1_OnClick(Sender) becomes event handler for Panel1.OncCick event.

For Delphi objects which are created from script during its executing, script handlers are automatically set or not depending on parameters of Add method (which is script extension provided by TekWSHControl).

Script procedure which has to be event handler must have one (if event has only Sender:TObject parameter) or two (if event has yet another params) parameters. First parameter will be the Sender and second (if present) will incapsulate the rest of native event parameters. For example, script procedure for Form1.OnCanResize (which has type TCanResizeEvent = procedure(Sender: TObject; var NewWidth, NewHeight: Integer; var Resize: Boolean);) can look such as (in VBScript):

Sub Form1_OnCanResize(Sender, Params)

... 'text of procedure

End Sub

where Sender is proxy object for Sender: TObject parameter, and Params is proxy for TCanResizeEventArgs instance incapsulating actual parameters passed to event handler (see more info about classes incapsulating actual parameters in T<event_name>EventArgs topics of help). So, the only difference from the way you usual work with event parameters in Delphi applications, is that in script procedure you have to include Params. (for current example) prefix with parameter's name.

Of course nobody prevents you from writing event handlers in Delphi application and calling any script routines from them instead of using mechanisms described above. But the way provided with TekWSHControl is just to let you assign script routines as event handler by just one line of code (and, besides of all, to assign handlers automatically for objects created in script). This is just your choise will you use it or not.


Ekas Software Windows Script Host Control for Delphi Help
Copyright (c)2002,2003 Ekas Software