Solved

InterBase Events in Delphi

Posted on 2003-12-10
29
3,469 Views
Last Modified: 2013-12-09
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
0
Comment
Question by:kacor
  • 18
  • 11
29 Comments
 
LVL 6

Expert Comment

by:BAlexandrov
ID: 9910957
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
0
 
LVL 10

Author Comment

by:kacor
ID: 9910960
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
0
 
LVL 6

Expert Comment

by:BAlexandrov
ID: 9910972
Example of working with events? Is'nt there one in Delphi?
I will install it here and try.
0
 
LVL 10

Author Comment

by:kacor
ID: 9911130
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
0
 
LVL 10

Author Comment

by:kacor
ID: 9911138
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
 ;
0
 
LVL 6

Expert Comment

by:BAlexandrov
ID: 9911233
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...
0
 
LVL 10

Author Comment

by:kacor
ID: 9911283
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
0
 
LVL 10

Author Comment

by:kacor
ID: 9911285
Otherwise since a good month I have 24 hours 256k symmetric DSL, this is very comfortable!!
0
 
LVL 6

Expert Comment

by:BAlexandrov
ID: 9911300
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?
0
 
LVL 10

Author Comment

by:kacor
ID: 9911488
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
0
 
LVL 6

Expert Comment

by:BAlexandrov
ID: 9911799
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
0
 
LVL 10

Author Comment

by:kacor
ID: 9912853
I've got it and now I have a program but late in this evening I'll try it

regards

Janos
0
 
LVL 10

Author Comment

by:kacor
ID: 9915500
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?
0
 
LVL 10

Author Comment

by:kacor
ID: 9915580
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
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 10

Author Comment

by:kacor
ID: 9915797
 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
0
 
LVL 10

Author Comment

by:kacor
ID: 9915939
or my mistake.  Of course I'd like to solve/finish this horror so every kind of modifying appreciated :o))
0
 
LVL 10

Author Comment

by:kacor
ID: 9915986
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.
0
 
LVL 6

Expert Comment

by:BAlexandrov
ID: 9916241
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!
0
 
LVL 10

Author Comment

by:kacor
ID: 9916330
haha with Set Registered = False in design time I've got first an error-free application
0
 
LVL 10

Author Comment

by:kacor
ID: 9916451
but the event didn't appear in the Delphi application
0
 
LVL 6

Expert Comment

by:BAlexandrov
ID: 9918732
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!
0
 
LVL 10

Author Comment

by:kacor
ID: 9918878
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
0
 
LVL 6

Expert Comment

by:BAlexandrov
ID: 9918933
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_!
0
 
LVL 10

Author Comment

by:kacor
ID: 9919344
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
0
 
LVL 6

Accepted Solution

by:
BAlexandrov earned 500 total points
ID: 9919411
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
0
 
LVL 10

Author Comment

by:kacor
ID: 9919761
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  
---------------------------

0
 
LVL 6

Expert Comment

by:BAlexandrov
ID: 9919927
Proceed to suggestion 1 :))
See the app that I have sent you
0
 
LVL 10

Author Comment

by:kacor
ID: 9923348
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
0
 
LVL 6

Expert Comment

by:BAlexandrov
ID: 9923719
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.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction: I have seen many questions on EE and elsewhere, asking about how to find either gaps in lists of numbers (id field, usually) ranges of values or dates overlapping date ranges combined date ranges I thought it would be a good …
Creating and Managing Databases with phpMyAdmin in cPanel.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now