daily pastebin goal
22%
SHARE
TWEET

fbevent

a guest Aug 10th, 2015 242 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.     Classes, SysUtils, FBEventMonitor, IBConnection, sqldb, FileUtil, Forms,
  9.     Controls, Graphics, Dialogs, StdCtrls;
  10.  
  11. type
  12.  
  13.     { TForm1 }
  14.  
  15.     TForm1 = class(TForm)
  16.         Button1: TButton;
  17.         Edit1: TEdit;
  18.         FBEventMonitor: TFBEventMonitor;
  19.         ConnMaster: TIBConnection;
  20.         ConnListener: TIBConnection;
  21.         ListBox: TListBox;
  22.         SQLTransaction: TSQLTransaction;
  23.         procedure Button1Click(Sender: TObject);
  24.         procedure FBEventMonitorEventAlert(Sender: TObject; EventName: string;
  25.             EventCount: longint; var CancelAlerts: boolean);
  26.         procedure FormCreate(Sender: TObject);
  27.     private
  28.         { private declarations }
  29.     public
  30.         { public declarations }
  31.     end;
  32.  
  33. var
  34.     Form1: TForm1;
  35.  
  36. implementation
  37.  
  38. {$R *.lfm}
  39.  
  40. { TForm1 }
  41.  
  42. procedure TForm1.FormCreate(Sender: TObject);
  43. begin
  44.     ConnMaster.DatabaseName := 'D:\dev\db\FOO.FDB';
  45.     ConnMaster.UserName := 'SYSDBA';
  46.     ConnMaster.Password := 'masterkey';
  47.     ConnMaster.LoginPrompt := False;
  48.     ConnMaster.Transaction := SQLTransaction;
  49.     ConnMaster.Open;
  50.  
  51.     ConnMaster.ExecuteDirect('RECREATE PROCEDURE send_custom(event_name varchar(127)) '+
  52.        'AS '+
  53.        'BEGIN '+
  54.        'POST_EVENT event_name; '+
  55.        'END ');
  56.     ConnMaster.Transaction.Commit;
  57.  
  58.     ConnListener.HostName:=ConnMaster.HostName;
  59.     ConnListener.DatabaseName:=ConnMaster.DatabaseName;
  60.     ConnListener.UserName:=ConnMaster.UserName;
  61.     ConnListener.Password:=ConnMaster.Password;
  62.     ConnListener.Open;
  63.  
  64.     FBEventMonitor.Connection := ConnListener;
  65.     FBEventMonitor.Events.Add('One');
  66.     FBEventMonitor.Events.Add('Two');
  67.     FBEventMonitor.Events.Add('Three');
  68.     FBEventMonitor.RegisterEvents;
  69.     FBEventMonitor.Registered := True;
  70.  
  71.     Edit1.Text := 'One';
  72. end;
  73.  
  74. procedure TForm1.FBEventMonitorEventAlert(Sender: TObject; EventName: string;
  75.     EventCount: longint; var CancelAlerts: boolean);
  76. begin
  77.     ListBox.Items.Add(EventName);
  78. end;
  79.  
  80. procedure TForm1.Button1Click(Sender: TObject);
  81. begin
  82.     ConnMaster.ExecuteDirect('execute PROCEDURE send_custom('+QuotedStr(Edit1.Text)+');');
  83.     ConnMaster.Transaction.CommitRetaining;
  84. end;
  85.  
  86. end.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top