Nil Object Exception on Window close

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?

Thanks.

What is the code in the Close event ?

1 Like

If there are any timers running on the window try explicitly turning them off in the close event.

1 Like

Are you using DataView ? Last version can potentially cause NilObject on windows close that Jim is working on…

I am using DataView however it is not being used on the window that is crashing. Does that matter?

I did try turning off all timers but it had no effect.

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

Should not…but I would suggest try with an older version, 1.15.5.2 is fine.

It is definitely related to having focus in a cell in a listbox. If I set focus to another control, the crash does not occur.

The ListBox is a Xojo ListBox or a DataView based one ?

It is a Xojo listbox.

It seems like the window close event is firing before the Listbox cell lostfocus event. Then when the lostfocus event fires, it no longer exists.

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
1 Like