program IBDACEventConsoleTest;
{$APPTYPE CONSOLE}
uses
SysUtils, IBC, IBCAlerter, Forms, Types, Windows;
type
TMyEventHandler =
class
public
procedure DoEventAlert(Sender: TObject; AEventName:
string; AEventCount: Longint);
end;
var
conn: TIBCConnection;
alerter: TIBCAlerter;
isShutdown: Boolean;
eventHandler: TMyEventHandler;
function ConsoleEventProc(CtrlType : DWord) : Bool;
stdcall;
far;
begin
case CtrlType
of
CTRL_C_EVENT,
CTRL_BREAK_EVENT,
CTRL_CLOSE_EVENT,
CTRL_LOGOFF_EVENT,
CTRL_SHUTDOWN_EVENT: isShutdown := True;
end;
Result := True;
end;
{ TMyEventHandler }
procedure TMyEventHandler.DoEventAlert(Sender: TObject; AEventName:
string; AEventCount: Integer);
begin
Writeln(Format('
Event: %s received. Count: %d', [AEventName, AEventCount]));
end;
begin
SetConsoleCtrlHandler(@ConsoleEventProc, True);
try
eventHandler := TMyEventHandler.Create;
try
conn := TIBCConnection.Create(
nil);
try
conn.LoginPrompt := False;
conn.Database := '
localhost/3051:tourism.fdb';
conn.Username := '
tourism';
conn.Password := '
tourism';
conn.Connect;
alerter := TIBCAlerter.Create(
nil);
try
alerter.OnEvent := eventHandler.DoEventAlert;
alerter.Connection := conn;
alerter.Events.Add('
Event1');
alerter.Active := True;
isShutdown := False;
while not isShutdown
do
begin
Application.HandleMessage;
end;
finally
alerter.Active := False;
alerter.Free;
end;
finally
conn.Disconnect;
conn.Free;
end;
finally
eventHandler.Free;
end;
except
on E:
Exception do
Writeln(E.ClassName, '
: ', E.
Message);
end;
end.