Sign in Join
Wiki copytemporary

TFBEventMonitor: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: TFBEventMonitor

OldNewLine
1+**TFBEventMonitor** ![](/wiki-images/9/9b/Tfbeventmonitor.png) in the FBEventMonitor unit is used to monitor named events sent from the [[Firebird]] database server. Events are typically generated by triggers on certain database operations.
2+
3+Using events means you can avoid regularly polling the database for status changes and can be useful in cases of high load.
4+
5+## Example
6+
7+Updating a memo with events received. Monitoring events E1 through E7.
8+
9+``` pascal
10+procedure TForm1.StartMonitor;
11+begin
12+ EventsM:=TFBEventMonitor.create(Self);
13+ EventsM.Connection:=IBConnection1;
14+ EventsM.Events.CommaText:='"E1",E2,E3,E4,"E5","E6","E7"'; //quotes are ignored
15+ EventsM.OnEventAlert:=OnFBEvent;
16+ EventsM.RegisterEvents; // will activate IBConnection1 if not connected
17+end;
18+
19+procedure TForm1.StopMonitor;
20+begin
21+ EventsM.UnRegisterEvents;
22+ EventsM.Free;
23+end;
24+
25+procedure TForm1.OnFBEvent(Sender: TObject; EventName: string;
26+ EventCount: longint; var CancelAlerts: boolean);
27+begin
28+ Memo1.Lines.Add(EventName+' occurred '+IntToStr(EventCount)+' times.');
29+end;
30+```
31+
32+The event monitor stops monitoring when the linked TIBConnection is disconnected and will not restart automatically. Use the TIBConnection.AfterConnect and TIBConnection.BeforeDisconnect event handlers to start and stop the monitoring automatically.
33+
34+The database server sends events to all connections registered for these events except for those created by the connection itself. Events are sent after a transaction is committed. Rolling back a transaction will cancel all events created in that transaction. fbeventstest.pp in the fcl packages/fcl-db/examples/ directory is a test/demo program that creates a stored procedure to send an event with an arbitrary name and uses a second connection to monitor the events sent.
35+
36+> **Warning:** TFBEventMonitor creates a thread to monitor incoming events. On Unix include cthreads or any other thread manager.
37+
38+## See also
39+
40+- [[Firebird|Using Firebird with FPC/Lazarus sqldb.]]
41+- Firebird documentation/readme files on events
42+- [Presentation on Firebird events](http://www.firebirdsql.org/file/documentation/papers_presentations/Power_Firebird_events.pdf)
43+
44+---
45+*From the Free Pascal wiki, page "TFBEventMonitor", as it stood on 2020-03-01 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history