Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Unregistering event alerter causing application to freeze


This question is answered. Helpful answers available: 1. Correct answers available: 1.


Permlink Replies: 2 - Last Post: Mar 26, 2018 7:48 AM Last Post By: Jeffrey Eib, Sr.
Jeffrey Eib, Sr.

Posts: 5
Registered: 4/25/05
Unregistering event alerter causing application to freeze  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 23, 2018 1:36 PM
I am using Delphi XE8 Enterprise Version 22.0.19027.8951 on Windows 7 to access a FireBird 2.5 database.

I am trying to implement an event notification system that will warn users when the data for the order that they are currently viewing has been changed by another user and refresh the order's data. In my database, when an order's data has changed, a trigger posts an event that incorporates the order number being changed into its name:

post_event 'ORDER-' || ordernum;

In my application, whenever the user changes the particular order that they are viewing, along with updating the data on the screen, I am trying to change the event name that the form is watching. Whenever the order number being viewed has changed, the following code is executed:

if fdevn_OrderChange.Active then
fdevn_OrderChange.Active := False; <-*** Application freezes here.

fdevn_OrderChange.Names.Clear;
fdevn_OrderChange.Names.Add(rs_AlertName + IntToStr(FOrderNumber)); // rs_AlertName = 'ORDER-'
fdevn_OrderChange.Active := True;

The first time through this, everything works fine. If an event is triggered, any user viewing the order being changed is notified and his screen is refreshed with the new data. However, if the user changes the order being viewed, the application freezes at the line marked above, as if it were stuck in an infinite loop. The only way to get out of it is to reset the application.

Tracing into the FireDAC source code, I found that the program always freezes in the block of code below at the line indicated:

procedure TFDCustomEventAlerter.Unregister;
begin
if not Active then
Exit;
FEventAlerterIntf.Options := nil;
FEventAlerterIntf.Handler := nil;
FEventAlerterIntf.Unregister; <-*** Application freezes here.
FEventAlerterIntf := nil;
end;

I can't step any further into the code here.

Is it not possible to change which event an TFDEventAlerter is watching during the run of a code? Why would unregistering an event alerter cause the application to freeze? Is there something that I should be doing first before unregistering the alerter?

Any help you can give will be greatly appreciated.

Jeffrey Eib, Sr.

Edited by: Jeffrey Eib, Sr. on Mar 23, 2018 1:37 PM
M. E.L.

Posts: 19
Registered: 2/7/02
Re: Unregistering event alerter causing application to freeze
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 24, 2018 8:22 AM   in response to: Jeffrey Eib, Sr. in response to: Jeffrey Eib, Sr.
The same happened to me.
It might be fixed in newer Firedac version, but that is what I did:

in IDE, set FDEventAlerter.Active to false and Options.AutoRegister to false

in programm, after connecting to database
FDEventAlerter.Register;
FDEventAlerter.Active := True;

then in programm, before dssconnecting from database:
FDEventAlerter.Active := False;

This works for me.

Mel

Edited by: M. E.L. on Mar 24, 2018 8:23 AM
Jeffrey Eib, Sr.

Posts: 5
Registered: 4/25/05
Re: Unregistering event alerter causing application to freeze  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 26, 2018 7:48 AM   in response to: M. E.L. in response to: M. E.L.
Thanks,

I thought that my problem was because I never called Register on the event alerter. So I added the call and tested again. Unfortunately I got the same result. The program still froze at setting the Active property to false.

This did get me thinking, though. My routine to set the Active property to false was being called from within the OnAlert event while refreshing the on screen data. I re-wrote the section of code that refreshes the data on screen to eliminate changing the alerter options, and everything now works as intended.

So, for any others that may run into the same problem, no changes to the event alerter can be made while within the OnAlert event. This will cause a call to the Unregister method which will freeze the application if called before the OnAlert event finishes.

Jeffrey

M. E.L. wrote:
The same happened to me.
It might be fixed in newer Firedac version, but that is what I did:

in IDE, set FDEventAlerter.Active to false and Options.AutoRegister to false

in programm, after connecting to database
FDEventAlerter.Register;
FDEventAlerter.Active := True;

then in programm, before dssconnecting from database:
FDEventAlerter.Active := False;

This works for me.

Mel

Edited by: M. E.L. on Mar 24, 2018 8:23 AM
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02