newObjects-logo.gif (1024 bytes) ScriptAggregate reference
AddEventHandler method

Adds code to handle event fired by the namespace object specified

variable = object.AddEventHandler(item, subitem, event, code, language)

variable boolean true if the operation was successful and false if not. Use lastError property to obtain error description
object ScriptAggregate Previously created ScriptAggregate object
item string Name of the namespace firing the events that will be captured by the script.
subitem string Name of the subitem of the namespace (item) if the desired event source is a subitem of the item. Can be empty string that means - the events will be captured from the item.
event string Event name for which the handler code is added
code string string containing the handler script code
language string Script language of the source code being added. The name must correspond to a language added by AddEngine method


This one and Connect methods are recommended only to the experienced programmers with deep COM knowledge. Script engines have different requirements to the items in order to sink their events. Additionally threading is important in that case you must take care about the thread that fires the events (see MSDN for some notes).

JScript requires items (or subitems) to support at least IProvideClassInfo interface in order to obtain event dispinterface information. JScript engine also checks for IDispatchEx thus one of these two interfaces will be enough if you are implementing the component that will fire events to the script

VBScript requires items (or subitems) to support IDispatchEx interface. Thus VBScript is much more problematic if you want to save some work when developing components for use with VB scripting.

What means subitem? Typically subitem is the name of the property that returns IDispatch (or packed in the VARIANT IUnknown or IDispatch) of another object.

Event name is the name of the method of the event dispininterface of the item (or subitem). Arguments of the event are passed as arguments of the internally generated by the script engine function (see below).

Code added must not contain head or footer of the function/subroutine declaration. Script engine generates function and uses this code as a body. For example in JScript if the item is MyItem and event is MyEvent (without parameters) function declaration will be:

function MyItem::MyEvent() {
    // code

In VBScript this will be:

Sub MyItem_MyEvent
    ' code
End Sub

You must care about the names of the items and events because their names form the function/subroutine declaration thus if their names are valid for the automation but not valid for the particular script language syntax - error will be genrated.

See also:

C++ Helper SCPHOSTCLNT::AddEventHandler method

newObjects Copyright newObjects 2001-2005