Access to Forms just being created

delphi package - automated exception handling
Post Reply
Sneak-L8
Posts: 6
Joined: Tue Apr 18, 2017 3:43 pm

Access to Forms just being created

Post by Sneak-L8 »

Hi,

the name of the topic sounds strange, but I don't know how to express it a better way :-)

Before using madExcept, I had my own ExceptionHandler established in Application.OnException. When I created a new form or dialog and there was an error inside the constructor Create, I was able to find this form in my exception handler via FindComponent.

When using madExcept I do not find this form anymore. I see hat everythings looks like before using madExcept except that the form has gone.

I think the form is already freed when madExcept takes over. Is there a possibility to have the same behaviour like OnException, so the form is not yet freed? I already tried to use stDontSync and stTrySyncCallOnSuccess with no change.

Bye
Sneak-L8

P.S. newest madExcept 4.0.17 and Delphi 7.1
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: Access to Forms just being created

Post by madshi »

The timing should not change. If the form was still there in Application.OnException, then it should also still be there in your madExcept exception handler.

Can you set a breakpoint in your form's OnDestroy handler to see if it gets called, with both madExcept enabled and disabled? Just to double check?
Sneak-L8
Posts: 6
Joined: Tue Apr 18, 2017 3:43 pm

Re: Access to Forms just being created

Post by Sneak-L8 »

Thanks. Testing by breakpointing Destroy was a good idea.

But, unfortunately behaviour differs between Application.OnException and madExcept. Using OnException the form is freed after the error form was created. Using madExcept the form is freed before my registered ExceptionHandler is called.

Is the a "Application.ProcessMessages" in you code with leads the form to be freed?

Bye
Sneak-L8
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: Access to Forms just being created

Post by madshi »

That seems weird. What's the callstack on the Destroy breakpoint with madExcept enabled vs disabled?
Sneak-L8
Posts: 6
Joined: Tue Apr 18, 2017 3:43 pm

Re: Access to Forms just being created

Post by Sneak-L8 »

With madExcept:
- TTGUserListEditDlg.Destroy
- TG (name of the project)

Without:
- TTGUserListEditDlg.Destroy
- TErrorForm.HandleException (initial class method of my exception handler)
- TTGMainForm.ApplException (method Application.OnException is assigned to)
- TG (name of the project)
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: Access to Forms just being created

Post by madshi »

Hmmmm... The Destroy method is called from within your exception handler (when not using madExcept)?
Sneak-L8
Posts: 6
Joined: Tue Apr 18, 2017 3:43 pm

Re: Access to Forms just being created

Post by Sneak-L8 »

Yes, within Form.ShowModal (presumably when performing an internal Application.ProcessMessages)
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: Access to Forms just being created

Post by madshi »

So basically it's just a timing problem and the form gets destroyed the first time when messages are handled, and without madExcept that just happens to be after your exception handler code has had the chance to run, while with madExcept enabled, for some reason messages seem to be handled before your handler had a chance to run?
Sneak-L8
Posts: 6
Joined: Tue Apr 18, 2017 3:43 pm

Re: Access to Forms just being created

Post by Sneak-L8 »

Yes, that's the point. Is there a way to do my handling things before ProcessMessages is performed? Or you even issue an Application.ProcessMessages?
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: Access to Forms just being created

Post by madshi »

When using the very latest madExcept build, you can set "madExcept.HandleMessagesInMainThread := false" in your initialization. However, doing so will make your VCL forms all appear frozen, as long as the madExcept exception handling is active.
Sneak-L8
Posts: 6
Joined: Tue Apr 18, 2017 3:43 pm

Re: Access to Forms just being created

Post by Sneak-L8 »

Hey, great. It works! Now, the form is still there when gathering additional DB information.

Thanks!

Bye
Sneak-L8
Post Reply