Programming => General => Topic started by: oldpicker on May 07, 2021, 06:46:17 am
Title: Sender:TObject in Custom Exception Handler is Nil
Post by: oldpicker on May 07, 2021, 06:46:17 am
I have written a custom exception handler which displays a customized error message when OnException. What I want to do here is moving the text cursor back to the TDBEdit that caused this exception, after the error message is displayed.
What I want to do here is moving the text cursor back to the TDBEdit that caused this exception, after the error message is displayed.
There is no way to know which control raised the exception. But if the TDBEdit was already focused when the exception is raised, I would expect it to regain the focus when the error dialog is closed.
The Sender of the OnException event is not the control that raised the exception. It is usually the object that caught the exception and called TApplication.HandleException() to trigger the OnException event. HandleException() has a Sender parameter that is passed to OnException. That is *usually* the TForm.
So, I find it a little odd that the Sender is nil instead. That means whichever object is calling HandleException() is not identifying itself. What does the call stack look like when the exception is raised?