This sample describes how to work with database events. TFDEventAlerter is used to receive event notifications.
You can find the TFDEventAlerter sample project at:
- Start | Programs | Appmethod 1.16 | Samples and then navigate to:
- Object Pascal\DataBase\FireDAC\Samples\Comp Layer\TFDEventAlerter\Main.
- Subversion Repository for Object Pascal: http://sourceforge.net/p/radstudiodemos/code/HEAD/tree/branches/RadStudio_XE8//Object%20Pascal/Database/FireDAC/Samples/Comp%20Layer/TFDEventAlerter/Main.
This sample uses the Use Connection Definition drop-down menu to select a connection definition. If the database supports events, then the application fills the supported event kinds.
You can register and unregister to an event. Click Fire events to start receiving the alerts when you are registered to the event.
How to Use the Sample
- Navigate to the location given above and open:
- Object Pascal: EventAlerter.dproj
- Press F9 or choose Run > Run.
- Select a connection definition from the Use Connection Definition drop-down menu.
- Select the event kind or leave Default.
- Click Register events to register to the database events in order to receive notifications.
- Click Fire events to trigger the events.
- Click Unregister events to unregister to the database events to stop receiving notifications.
- Note: The notifications are shown on the TMemo.
- Use Connection Definition drop-down menu:
The menu shows all the connections defined on the file at C:\Users\Public\Documents\Embarcadero\Studio\FireDAC\FDConnectionsDefs.ini.
If the database supports events, then the application fills the supported event kinds.
Once the connection is defined, the Register events button is enabled to register and start accepting events.
- Register events button:
Once you click Register events, the rest of buttons are enabled.
- Fire events button:
Click Fire events to trigger the alerts.
When there is an alert, the OnAlert event handler is called and the event name and arguments are shown on the TMemo.
When there are no alerts for a "Timeout" period of time, the OnTimeout event handler is called and the Timeout message appears on the TMemo. The timeout period is set by specifying the Timeout argument of the Options property of the TFDEventAlerter.
The value is set to
1000 ms by default (1 sec).
- Unregister events button: