Page 1 of 1

Access to Forms just being created

Posted: Tue Apr 18, 2017 4:59 pm
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

Re: Access to Forms just being created

Posted: Tue Apr 18, 2017 5:11 pm
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?

Re: Access to Forms just being created

Posted: Wed Apr 19, 2017 10:30 am
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

Re: Access to Forms just being created

Posted: Wed Apr 19, 2017 10:46 am
by madshi
That seems weird. What's the callstack on the Destroy breakpoint with madExcept enabled vs disabled?

Re: Access to Forms just being created

Posted: Wed Apr 19, 2017 10:58 am
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)

Re: Access to Forms just being created

Posted: Wed Apr 19, 2017 11:00 am
by madshi
Hmmmm... The Destroy method is called from within your exception handler (when not using madExcept)?

Re: Access to Forms just being created

Posted: Wed Apr 19, 2017 11:04 am
by Sneak-L8
Yes, within Form.ShowModal (presumably when performing an internal Application.ProcessMessages)

Re: Access to Forms just being created

Posted: Wed Apr 19, 2017 12:21 pm
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?

Re: Access to Forms just being created

Posted: Wed Apr 19, 2017 6:05 pm
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?

Re: Access to Forms just being created

Posted: Wed Apr 19, 2017 8:27 pm
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.

Re: Access to Forms just being created

Posted: Wed Apr 19, 2017 9:52 pm
by Sneak-L8
Hey, great. It works! Now, the form is still there when gathering additional DB information.

Thanks!

Bye
Sneak-L8