Wiki copymirror

This is a mirror of the wiki at pascal.chat. Editing, history and sign-in are there.

TFBEventMonitor

English · Русский

TFBEventMonitor 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.

Using events means you can avoid regularly polling the database for status changes and can be useful in cases of high load.

Example

Updating a memo with events received. Monitoring events E1 through E7.

pascal
procedure TForm1.StartMonitor;
begin
  EventsM:=TFBEventMonitor.create(Self);
  EventsM.Connection:=IBConnection1;
  EventsM.Events.CommaText:='"E1",E2,E3,E4,"E5","E6","E7"'; //quotes are ignored
  EventsM.OnEventAlert:=OnFBEvent;
  EventsM.RegisterEvents;   // will activate IBConnection1 if not connected
end;

procedure TForm1.StopMonitor;
begin
  EventsM.UnRegisterEvents;  
  EventsM.Free;
end;

procedure TForm1.OnFBEvent(Sender: TObject; EventName: string;
  EventCount: longint; var CancelAlerts: boolean);
begin
  Memo1.Lines.Add(EventName+' occurred '+IntToStr(EventCount)+' times.');
end;

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.

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.

Warning: TFBEventMonitor creates a thread to monitor incoming events. On Unix include cthreads or any other thread manager.

See also


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.

Revision 1, last changed by WikiArchive .