Knowledgebase: FAQ
7.x: EurekaLog is not called when I am using TApplicationEvents component or (VCL.)AppEvnts unit
Posted by Aleksandr Alekseev on 28 November 2014 17:57

Problem:

I have old code, which is working fine with previous version of EurekaLog (5.x/6.x). It does not work with EurekaLog 7. I set all options as outlined in guides, but EurekaLog is not invoked automatically for exceptions. My code uses TApplicationEvents component (from VCL.AppEvnts unit).

Reason:

Previous EurekaLog versions ignored whenever Application.OnException event was set or not. This behavious conflicted with default behaviour of Application object.

EurekaLog 7 changes the way to work with Application.OnException event. EurekaLog 7 respects this event: if event handler is NOT set - then EurekaLog will handle exceptions automatically; if event handler is set - then EurekaLog assumes that you want to handle exceptions by yourself.

TApplicationEvents component from VCL.AppEvnts unit overrides Application.OnException event handler to provide TApplicationEvents.OnException.

The problem is that Delphi VCL do not have multi-cast events, thus it is not possible to have both TApplicationEvents and EurekaLog to handle TApplication.OnException. Since EurekaLog is initialized very first and TApplicationEvents is constructed inside form later - TApplicationEvents will be the last one to set TApplication.OnException handler, it wins.

Solution:

That depends on what you want.

  1. If you do not need TApplicationEvents component or can live without it (e.g. by assigning event handlers for TApplication manually instead of using component) - do this. Remove TApplicationEvents component and (important: see below) remove VCL.AppEvnts unit.
  2. If you need TApplicationEvents component:
    1. If you want EurekaLog to handle exception - you need to pass exception to EurekaLog:
      1. Assign TApplicationEvents.OnException event handler and call EBase.HandleException to invoke EurekaLog for this exception.
    2. If you want to run your custom code for each exception (e.g. if you already have a TApplicationEvents.OnException handler):
      1. You can call EBase.HandleException inside your own TApplicationEvents.OnException handler to invoke EurekaLog's processing for specified exception.

Important Note:

TApplicationEvents component overrides TApplication.OnException event even if you do not assign TApplicationEvents.OnException property. Also, (in some Delphi versions) VCL.AppEvnts unit overrides Application.OnException event even if no TApplicationEvents component is created. Be sure to manually remove VCL.AppEvnts unit from your application if it is not needed.

Note:

If you did not assign TApplicationEvents.OnException hander - then RTL will invoke Application.ShowException to show error dialog. EurekaLog can catch this call and show EurekaLog error dialog instead - but only if "low-level hooks" option is enabled.

See also:


Help Desk Software by Kayako Resolve