I am getting a Nil Object Exception on Window close which is very difficult to track down. When I step through the debugger, it just stops - and then when I hit Resume, it crashes.
If I place self.hide in the CancelClose event and then Return True, it doesn’t crash.
I am suspicious the problem is in the LostFocus event of an object but I can’t seem to trap the error.
I created a boolean property called WindowClosing and then set that to True in the CancelClose event, and then in objects with a LostFocus event I entered:
If WindowClosing then Return
at the beginning to hopefully stop this Nil Object Exception but I am still getting this error.
These are tough errors to track down. Are there any hints as to how to catch them?
If InvoiceModified then
//s = the text you want displayed
//sOK - what the OK button says
//sCancel - what the Alternative button says
//sExplanation = Additional text or information
Dim i as Integer
i = App.CONFIRM("Save Changes?","Save","Don't Save","","")
If i = 1 then //Save the Invoice
If Check_for_Errors = False then
sInvNumber = SaveInvoice
Else
Return True
End If
Elseif i = 2 then //Discard changes
Else
Return True
End if
Else
WindowClosing = True
Timer_CheckGlobal.Mode = timer.ModeOff
Timer_OptionKey.Mode = timer.ModeOff
End If
It looks like I solved the problem by changing focus to a different control in the window close event.
This code works:
If InvoiceModified then
//s = the text you want displayed
//sOK - what the OK button says
//sCancel - what the Alternative button says
//sExplanation = Additional text or information
Dim i as Integer
i = App.CONFIRM("Save Changes?","Save","Don't Save","","")
If i = 1 then //Save the Invoice
If Check_for_Errors = False then
sInvNumber = SaveInvoice
Else
Return True
End If
Elseif i = 2 then //Discard changes
Else
Return True
End if
Else
WindowClosing = True
fldDate.SetFocus
End If
I’ve got this EXACT SAME problem but not sure how to implement the “fix” noted here. I have a modal window with a few listboxes (actually DataView) and a few buttons inside the main window. When I edit a cell in the listbox, the program crashes (“An exception of NilObjectException was not handled. The application must shut down.”) when I try to close the modal window.
While I have never encountered this, my interpretation of the replies by @David_Schlam is that you just need to shift the focus to outside the listbox / dataview prior to the close event. So assuming you have another control that can accept focus (e.g. an enabled text field), try adding a CancelClose event to the window and in it place a TextField1.SetFocus, where TextField1 is the name of some control that can accept the focus on each OS.
Thanks for taking the time to respond, Douglas. Unfortunately, I interpreted the “fix” the same way as you and had already tried putting a textfield on the modal window to allow TextField1.SetFocus in the CancelClose … No Love!!!