fredycc Posted August 5, 2011 Posted August 5, 2011 Hi Mr. Farshad congratulations on your good work. My case is the next I have a little vcl project with Delphi that connects to a firebird database with zeos, each instance register events that work with firebird for example after insert, after update or after delete, the case is if the event is fired for a trigger I refresh the dbgrid to display maybe a new record, see new update record or send a information message to all instances that are listen the event, how can I same behavior with unigui, is it possible?, I tried but only vcl application detects the event, maybe because unigui works with sessions. regards. Quote
Administrators Farshad Mohajeri Posted August 5, 2011 Administrators Posted August 5, 2011 Hi, Are those events regular Delphi events. What is the mechanism you use to propagate events between sessions? In uniGUI you should be able to register events like you do in a VCL app. When event is received this does not automatically refresh DBGrid. You must call UniDBGrid.Refresh yourself. However, UniDBGrid.Refresh should be called only in a browser generated event. For this you need to use a UniTimer which will poll server once a while (say once per 30 secs). When trigger is called you must set an internal flag. When timer event is called, if flag is True you will clear the flag and call Grid.Refresh. This method is not very efficient because it will call refresh only on each timer tick not sooner. Quote
fredycc Posted August 6, 2011 Author Posted August 6, 2011 Hi, Are those events regular Delphi events. What is the mechanism you use to propagate events between sessions? In uniGUI you should be able to register events like you do in a VCL app. When event is received this does not automatically refresh DBGrid. You must call UniDBGrid.Refresh yourself. However, UniDBGrid.Refresh should be called only in a browser generated event. For this you need to use a UniTimer which will poll server once a while (say once per 30 secs). When trigger is called you must set an internal flag. When timer event is called, if flag is True you will clear the flag and call Grid.Refresh. This method is not very efficient because it will call refresh only on each timer tick not sooner. Thank you for answer Mr. Farshad, I use Zeos components to connect with firebird, in this set of components exist one called TZIBEventAlerter in this one I can register events and catch it, this can be a little example of how use this component, Registering 2 events in Delphi: procedure TfrmEvents.FormCreate(Sender: TObject); begin dmEvents.ZIBEventAlerter1.Events.Add('NEW_EMPLOYEE'); dmEvents.ZIBEventAlerter1.Events.Add('UPD_EMPLOYEE'); dmEvents.ZIBEventAlerter1.RegisterEvents; end; procedure TdmEvents.ZIBEventAlerter1EventAlert(Sender: TObject; EventName: string; EventCount: longint; var CancelAlerts: boolean); begin // If a registered event was received then its name will send a message if EventName='NEW_EMPLOYEE' then showmessage('New employee has been added') else if EventName='UPD_EMPLOYEE' then showmessage('A record has been updated, please refresh grid'); end; Trigger in firebird: CREATE TRIGGER TRIG_NEW_EMP FOR EMPLOYEES AFTER INSERT AS BEGIN POST_EVENT "NEW_EMPLOYEE"; END CREATE TRIGGER TRIG_UPD_EMP FOR EMPLOYEES AFTER UPDATE AS BEGIN POST_EVENT "UPD_EMPLOYEE"; END I think it is important to mention, How events work: network level The client has a regular connection to Firebird server at its port (3050 by default, but can be changed). When it is registering for events, it sends the request over that connection. The server opens another connection at some random port (4012 for example) and sends that port number to the client. The client then connects to that port. This is called the secondary connection, and it is used only for events. In future the server will send all event notifications over that connection http://www.firebirdsql.org/file/documentation/papers_presentations/Power_Firebird_events.pdf I will try create ZIBEventAlerter onruntime, maybe works. Thanks for your time and regards. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.