InterBase Events in Delphi

Hi Experts,

I made a simple application consisting of the Main form, on which there are the following components:
    IBEvents1: TIBEvents;
    IBDatabase1: TIBDatabase;
    IBTransaction1: TIBTransaction;
The IBDatabase1 is connected to Database Name = path\xx.gdb, and there are added Event1 and Event2 to IBEvents1.Events. This events were earlier declared in the database xx.gdb.

Running this simple application I've got the following message:
.
---------------------------
Debugger Exception Notification
---------------------------
Project Events.exe raised exception class EIBClientError with message 'Database name is missing'. Process stopped. Use Step or Run to continue.
---------------------------
OK   Help  
---------------------------

and I can't continue. What have I made wrong?

Thanks for every help in advance

with best regards

Janos
LVL 10
kacorretiredAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BAlexandrovCommented:
I don't have delphi here to check out but is something simple because I can't remember any problems regarding this...
See if you have set default transaction of TIBDatabase and default Database of the TIBTransaction

HTH
Bojidar Alexandrov
kacorretiredAuthor Commented:
I'd like to get a complete functioning example because I work with this question over 6 months but I can't reach succes. If you could post me a complet working example you'll get the points. My hardware is: P4-1600 ASUS P4S533 512MB RAM Matrox Mistique 200 W2kSP2 Delphi6Ent and now I'll try to change IB6 to IB7.1Eval

Janos
BAlexandrovCommented:
Example of working with events? Is'nt there one in Delphi?
I will install it here and try.
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

kacorretiredAuthor Commented:
Event's declaration: (from metadata)
==============

CREATE TRIGGER "TR_POST_EVENT" FOR "RENDELESEK"
ACTIVE AFTER INSERT POSITION 0
AS
  BEGIN
    IF (NEW.RENDELESERTEK >= 500000) THEN
                    post_event 'nagy_rendeles';
  END
 ;

Form1 declaration (
===============

unit Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, IBDatabase, IBEvents, StdCtrls, ComCtrls;

type
  TForm1 = class(TForm)
    RichEdit1: TRichEdit;
    Button1: TButton;
    IBDatabase1: TIBDatabase;
    IBTransaction1: TIBTransaction;
    IBEvents1: TIBEvents;
    procedure IBEvents1EventAlert(Sender: TObject; EventName: String;
      EventCount: Integer; var CancelAlerts: Boolean);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.IBEvents1EventAlert(Sender: TObject; EventName: String;
  EventCount: Integer; var CancelAlerts: Boolean);
begin
  MessageDlg('Delphi message: ' + EventName + ' event occured',
              mtInformation, mbOKCancel, 0);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  IBDatabase1.Connected := True;
  IBTransaction1.Active := True;
  IBEvents1.Registered := True;
end;

end.

======================

Please write if you need some more

Janos
kacorretiredAuthor Commented:
translated

CREATE TRIGGER "TR_POST_EVENT" FOR "ORDERS"
ACTIVE AFTER INSERT POSITION 0
AS
  BEGIN
    IF (NEW.ORDER_VALUE >= 500000) THEN
                    post_event 'big_order';
  END
 ;
BAlexandrovCommented:
Plase post also the text of dfm of the form1 to be able to make same example.
Here I have Firebird 1.5 - hope that this will not mess up - I have used events with IB 6 also...
kacorretiredAuthor Commented:
In the meantime I have reinstalled IB6 because I'm fighting for installing IB7eval(((((

OK
May I send them directly, Iwoun't overload the EE-site? Do you need the whole db and the delphi apll?
Janos
kacorretiredAuthor Commented:
Otherwise since a good month I have 24 hours 256k symmetric DSL, this is very comfortable!!
BAlexandrovCommented:
Yes, it will be easyer (anyway I am at work now) if you send them to me directly - use: bojo at developer.bg
I have not tryed IB7... did you seen its price beforehand?
kacorretiredAuthor Commented:
Earlier otherwise I placed this question under "Events" in this topic :o))))))
http://www.experts-exchange.com/Databases/Interbase/Q_20699828.html
but at that time I had only few points. Life is hard...
Janos
BAlexandrovCommented:
I have checked your app at home - during lunch break :). There I have Delphi 5 and Firebird 1.5 rc7

problem 1 - Set Registered = False in Design Time of TIBEventAlerter
problem 2 - Attach dsign time IBEvents1EventAlert event handler back to IBEvents1 onEventAlert
suggestion 1 - Before unload of application do IBEvents1.registered=false and IBDatabase1.conected=false in this order.
suggestion 2 - see if you really need snapshot transaction - you use this mode of IBTrans1
suggestion 3 - It is confusing to have event with same name as an exception defined in the database - consider change their names.

You will receive the event after you insert from elsewhere new record with RENDELESERTEK >= 500000 and do a Commit!

If it still does not work will make the project here and will send you working app.

HTH
Bojidar Alexandrov
kacorretiredAuthor Commented:
I've got it and now I have a program but late in this evening I'll try it

regards

Janos
kacorretiredAuthor Commented:
Now I'm back.
"suggestion 3 - It is confusing to have event with same name as an exception defined in the database - consider change their names."

if the exeption name differs from the name in Delphi, how can they meet each other?
kacorretiredAuthor Commented:
otherwise the trigger has the name TR_POST_EVENT and this posts the event "nagy_rendeles" and I mean I have to give this indentifier as requested event in the Delphi's Event Alerter Events. What is your meaning about?

Janos
kacorretiredAuthor Commented:
 object IBDatabase1: TIBDatabase
    Connected = True
    DatabaseName = 'E:\TanfolyamokIB\Az InterBase\Adatbazis\RENDELESEK.GDB'
    Params.Strings = (
      'user_name=sysdba'
      'password=masterkey')
    LoginPrompt = False
    DefaultTransaction = IBTransaction1
    IdleTimer = 0
    SQLDialect = 3
    TraceFlags = []
    AllowStreamedConnected = False
    Left = 16
    Top = 216
  end
  object IBTransaction1: TIBTransaction
    Active = True
    DefaultDatabase = IBDatabase1
    Params.Strings = (
      'read_committed'
      'rec_version'
      'nowait')
    AutoStopAction = saNone
    Left = 56
    Top = 216
  end
  object IBEvents1: TIBEvents
    AutoRegister = False
    Database = IBDatabase1
    Events.Strings = (
      'nagy_rendeles')
    Registered = True
    OnEventAlert = IBEvents1EventAlert
    Left = 240
    Top = 216
  end

using this settings I get the following error message:
---------------------------
Debugger Exception Notification
---------------------------
Project Events.exe raised exception class EIBClientError with message 'Database name is missing'. Process stopped. Use Step or Run to continue.
---------------------------
OK   Help  
---------------------------

and I am playing with this message since half year. If this runs at you it can be a hardversomething.
Janos
kacorretiredAuthor Commented:
or my mistake.  Of course I'd like to solve/finish this horror so every kind of modifying appreciated :o))
kacorretiredAuthor Commented:
Bojidar, If you read my story here please give step by step what have I to do. but without laughing :-))).

Hasta mañana! I go to slep.
BAlexandrovCommented:
No problem Janos. To get rid of this error:
From your post:
 object IBEvents1: TIBEvents
    AutoRegister = False
    Database = IBDatabase1
    Events.Strings = (
      'nagy_rendeles')
********* - here is the problem. Set Registered = False in design time and only set it to true at runtime as you do already.
    Registered = True
*********
    OnEventAlert = IBEvents1EventAlert
    Left = 240
    Top = 216
  end
----------------
Probably components are created in wrong order during start up and it tries to activate Events without database.

About the suggestion. Events and Exceptions in IB are completely different things. Exceptions can be raised with "Exception" statements. Reference - Working with Stored Procedures -> Exceptions in Data Definition Guide.
When you post an event it is just a string(but constant one) and you have to match it in IBEventAlerter in Delphi.

Try this and say what is the result. Also do not forget about the second problem - your event handler of IBEventAlerter is somehow detached - set it back.

Leka nosht!
kacorretiredAuthor Commented:
haha with Set Registered = False in design time I've got first an error-free application
kacorretiredAuthor Commented:
but the event didn't appear in the Delphi application
BAlexandrovCommented:
Now Problem 2 :)

Click on TIBEvents, Events page of Object Inspector and from combo box of onEventAlert select your handler - it is not attached now - attach it!
kacorretiredAuthor Commented:
IBEvents1EventAlert was earlier set

Dummy question: if I set by using IBConsole the RENDELESERTEK > 500000, the NEW.RENDELESERTEK get this value? Now I am totally disturbed. The Events application runs but I get no signal when RENDELESERTEK will greater as above set
BAlexandrovCommented:
It is not set - it was detached for some reason. Either attach it back, or delete the handler and make it again.

From IBConsole just issue and insert  into with required values (there was some not null ones - supply them also) and _commit_!
kacorretiredAuthor Commented:
this didn't help unfortunately. Now I'll try with IB7.1 may be it helps, may be not. Some specialities/functions of IB won't work normal on this configuration or I make something wrong.

All this programming  is sometimes like a  black art or a magic because once you make something and works, sometimes the same not. You get from somewhere an impulse and all of york is away.... Simply inexplicable. And this is worst then the battles of Don Quijote :-)

I remade TForm1.FormCreate procedure it didn't help. Probably first  I delete the whole project and reconsruct it this is not big work and later I'll try with ib71
BAlexandrovCommented:
Here I will post .pas and .dfm file contents of the form1 and will send you the complete project.
Your database structure and trigger are right. Just drop the exception - it is not needed.

Make this insert from IBConsole and do a commit
INSERT INTO RENDELESEK (rendelesertek,UGYFELAZ,FIZETESMODJA) values (1000000,14,'kp');

PAS
***********
unit Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, IBDatabase, IBEvents, StdCtrls, ComCtrls;

type
  TForm1 = class(TForm)
    RichEdit1: TRichEdit;
    Button1: TButton;
    IBDatabase1: TIBDatabase;
    IBTransaction1: TIBTransaction;
    IBEvents1: TIBEvents;
    procedure IBEvents1EventAlert(Sender: TObject; EventName: String;
      EventCount: Integer; var CancelAlerts: Boolean);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.IBEvents1EventAlert(Sender: TObject; EventName: String;
  EventCount: Integer; var CancelAlerts: Boolean);
begin
  MessageDlg('Delphi üzenet: ' + EventName + ' esemény bekövetkezett',
              mtInformation, mbOKCancel, 0);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  IBDatabase1.Connected := True;
  IBTransaction1.Active := True;
  IBEvents1.Registered := True;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  IBEvents1.Registered := False;
  IBDatabase1.Connected := False;
end;

end.


DFM
**********
object Form1: TForm1
  Left = 192
  Top = 107
  Width = 380
  Height = 287
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  OnDestroy = FormDestroy
  PixelsPerInch = 96
  TextHeight = 13
  object RichEdit1: TRichEdit
    Left = 8
    Top = 8
    Width = 345
    Height = 209
    Lines.Strings = (
      'Ebben az alkalmazasban TIBDatabase komponenssel kapcsolodunk a '
      'Rendelesek.GDB adatbazishoz.'
     
      'A TIBEvents komponens segitsegevel jelezzuk az adatbazis altal '
      'elkuldott esemenyt, amely a kovetkezo: '
      '   nagy_rendeles'
     
      'A form var az adatbazisbol erkezo nagy_rendeles esemenyre, es '
      'tajekoztat bennunket arrol, ha mar bekovetkezett.'
     
      'Az alkalmazas leallitasahoz kattintsunk a STOP gombra.')
    TabOrder = 0
  end
  object Button1: TButton
    Left = 111
    Top = 224
    Width = 75
    Height = 25
    Caption = 'STOP'
    TabOrder = 1
  end
  object IBDatabase1: TIBDatabase
    DatabaseName = 'LocalHost:E:\TanfolyamokIB\Az InterBase\Adatbazis\RENDELESEK.GDB'
    Params.Strings = (
      'user_name=sysdba'
      'password=masterkey')
    LoginPrompt = False
    DefaultTransaction = IBTransaction1
    IdleTimer = 0
    SQLDialect = 3
    TraceFlags = []
    AllowStreamedConnected = False
    Left = 16
    Top = 216
  end
  object IBTransaction1: TIBTransaction
    Active = False
    DefaultDatabase = IBDatabase1
    Params.Strings = (
      'read_committed'
      'rec_version'
      'nowait')
    AutoStopAction = saNone
    Left = 56
    Top = 216
  end
  object IBEvents1: TIBEvents
    AutoRegister = False
    Database = IBDatabase1
    Events.Strings = (
      'nagy_rendeles')
    Registered = False
    OnEventAlert = IBEvents1EventAlert
    Left = 240
    Top = 216
  end
end

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kacorretiredAuthor Commented:
I have completely rebuild the appl and aftre closing the apll I got the message:
---------------------------
Debugger Exception Notification
---------------------------
Project Project1.exe raised exception class EIBInterBaseError with message 'invalid database handle (no active connection)'. Process stopped. Use Step or Run to continue.
---------------------------
OK   Help  
---------------------------

BAlexandrovCommented:
Proceed to suggestion 1 :))
See the app that I have sent you
kacorretiredAuthor Commented:
Hi Bojidar,

it was great, thanks. Only a last question: how can I set this information window to be every time on the top? because now I had to clean the screen to see it :-)

Some explication for the future: this belongs to a database (RENEDELESEK.GDB) wich has the table RENEDELESEK including the following 3 columns too: rendelesertek, UGYFELAZ, FIZETESMODJA
BAlexandrovCommented:
May be adding this line in on EventAlert handler before MessageDlg will do it
Application.BringToFront;

Consider to log the information in the richedit control instead of showing a window because until message is closed no more events can be intercepted.

Use my email for future questions.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Databases

From novice to tech pro — start learning today.