MDAC 2.5 SDK - ADO


 

How Event Handlers Work Together

See Also

All the event handlers in the ConnectionEvent and RecordsetEvent families must be implemented, regardless of whether you actually use events. The amount of implementation work you have to do depends on your programming language. For more information, see ADO Event Instantiation by Language.

Will and Complete event handlers can be used in pairs or separately.

Paired Event Handlers

Unpaired Event Handlers

You can turn off event notifications for any event by returning adStatusUnwantedEvent in the status parameter. For example, when your Complete event handler is called the first time, return adStatusUnwantedEvent. You will subsequently receive only Will events.

Single Will event handlers can be useful when you want to examine the parameters that will be used in an operation. You can modify those operation parameters or cancel the operation.

Alternatively, leave Complete event notification enabled. When your first Will event handler is called, return adStatusUnwantedEvent. You will subsequently receive only Complete events.

Single Complete event handlers can be useful for managing asynchronous operations. Each asynchronous operation has an appropriate Complete event.

For example, it can take a long time to populate a large Recordset object. If your application is appropriately written, you can start a Recordset.Open(...,adAsyncExecute) operation and continue with other processing. You will eventually be notified when the Recordset is populated by an ExecuteComplete event.

Single Event Handlers and Multiple Objects

The flexibility of a programming language like Microsoft Visual C++ enables you to have one event handler process events from multiple objects. For example, you could have one Disconnect event handler process events from several Connection objects. If one of the connections ended, the Disconnect event handler would be called. You could tell which connection caused the event because the event handler object parameter would be set to the corresponding Connection object.

Note   This technique cannot be used in Visual Basic because that language can correlate only one object to an event.

Multiple Event Handlers and Single Operations

It is possible to associate one ADO object and its operations to multiple sets of events. For example, you could create multiple WillChangeField events so that each performs a particular field validation edit. If a field were about to change, one Will event could validate some aspect of the field value, then another Will event could validate a different aspect.

Preferably, you could simply perform or call all your edits from a single event handler.