A list of products available on this site
Documentation for XtraMania's xtras
Prices and links to the online store
Xtras, PDFs, samples
Have a question? Ask us!
Logo. www.xtramaina.com  
Home Search E-mail
VbScriptXtra Reference/objAuto.EventsHandler





VOID if events are not handled.

Instance of parent script which handles events generated by automation object.


VOID to stop handling events.

Instance of parent script which will handle events generated by automation object.


Use EventsHandler property to set a handler for Automation events generated by the wrapped Automation object.

Use ObjectBrowserXtra to see which Automation objects support events. Any Automation object may provide an outgoing interface describing which events it can fire.

After EventsHandler property is set to a valid parent script instance, wrapper starts listening for events. Once a particular event occurs, wrapper tries to call a corresponding method of the attached parent script instance. Event parameters are passed as Lingo property list. Using Lingo list allows event handler to return values via parameters passed by reference.

The code for event handler parent script may look like:

-- Sample EventHandler parent script
on new me
  return me

on SomeEventName me, argsList
  put "SomeEventName fired with arg1="&arg1&&"arg2="&arg2

on IncomingEvent me, event, args
  put event,args

Events handler parent script gets every event twice. The first event is sent in a direct form:
on eventName me, argsList
Then the universal handler is called:
on IncomingEvent me, EventSymbol, argsList
This improvement helps discovering what is sent by a COM Automation object. Note: IncomingEvents gets argsList modified by the first handler (if any).


Sample below demonstrates using events with ADODB.Connection object:

-- *******************************************************
-- Here is the code for EventsHandler parent script
on new me
  return me

on IncomingEvent me, event, args
  put event,args

on ConnectComplete me, args

  put "ConnectComplete"
  if(adStatus<>1) then alert pError.Description

on Disconnect me, args

  put "Disconnect"

on ExecuteComplete me, args

  put "ExecuteComplete"

on InfoMessage me, args

  put "InfoMessage"

on WillConnect me, args

  put "WillConnect"

  -- Creating new connection string
  cnnStr="Provider=Microsoft.Jet.OLEDB.4.0;" -- Microsoft Jet provider for MS Access databases
  cnnStr=cnnStr&"Data Source=D:\Temp\TestDB.mdb;"
  -- return it to the connection object via referenced parameter

on WillExecute me, args

  put "WillExecute"

-- End of the code for EventsHandler parent script
-- *******************************************************

Name this script as "ConnectionEvents". Then try to execute following lines right in Director's messages window:

  -- Setting debug mode to true

  -- Creating an instance of the ADODB.Connection object
  cnn=createObject(xtra "VbScriptXtra","ADODB.Connection")

  -- Creating an instance of the events handler parent script

  -- Attaching handler to a wrapper

  -- Opening connection without explicitly specifying connection params
  -- Connection string should be set by the events handler

To get more information about ADO events you may use ObjectBrowserXtra or see ADO documentation.

Site homeSearchContact author © Eugene Shoustrov. www.xtramania.com