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 | Embarcadero RAD Studio Alexandria | Samples and then navigate to:
- Object Pascal\DataBase\FireDAC\Samples\Comp Layer\TFDEventAlerter\Main.
- Subversion Repository:
- You can find Delphi code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.
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:
- Delphi: 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: