To use TIBEvents in your application:
1. Create a trigger or stored procedure on the InterBase server which will post
an event.
2. Add a TIBDatabase and a TIBEvents component to your form.
3. Add the events to the Events list and register them with the event manager.
4. Write an OnEventAlert event handler for each event.
Events are passed by triggers or stored procedures only when the transaction under
which they occur is posted. In addition, InterBase consolidates events before posting
them. For example, if an InterBase trigger posts 20 x STOCK_LOW events within a
transaction, when the transaction is committed these will be consolidated into a single
STOCK_LOW event, and the client will only receive one event notification.
For more information on events, refer to “Working with Events” in the InterBase 6
Programmer’s Guide.
Setting up event alerts
Double click on the ellipsis button (...) of the Events property add an event to the Events
list. Each TIBEvents component can handle up to 15 events. If you need to respond to
more that 15 events use more that one TIBEvents component. If you attempt to add too
many events at runtime, an exception will be raised.
To add an event to the Events list use the following code
TIBEvents.Events.Add( 'STOCK_LOW')
Writing an event handler
OnEventAlert is called every time an InterBase event is received by an IBEvents
component. The EventName variable contains the name of the event that has just been
received. The EventCount variable contains the number of EventName events that have
been received since OnEventAlert was last called.
To cancel interest in any further events, set CancelAlerts to True. If you later decide that
you want to receive events again, call the QueueEvents method. You cannot call
RegisterEvents, UnregisterEvents, QueueEvents or CancelEvents from within an
OnEventAlert event handler.
OnEventAlert runs as a separate thread to allow for true asynchronous event processing,
however, the IBEvents component provides synchronization code to ensure that only one
OnEventAlert event handler executes at any one time.
Partager