Timer Nil Object Exception

I have a timer on a window (named “Invoice”) in a Xojo desktop app (v2013 r3.3) that is throwing a Nil Object Exception on the line:

Timer_CheckGlobal.Mode = Timer.ModeSingle

The line is in a method of the “Invoice” window. The timer “Timer_CheckGlobal” exists on the window.

What can make a timer throw a Nil Object Exception like this?

Sorry, but the Timer_CjeckGlobal exists on the window as a dropped instance from the Library or as a Property? If the later, you should instantiate it first using: Timer_CheckGlobal = new Timer

If you have the Timer as an implicit instance (object dropped from the Library) to the Tray, then I think it should work.

As it turns out, the window was closing and the method was running after the window CancelClose event. Since the window was cancelled, nothing needed to be done or saved so the Method could just be skipped.

I created a property on the invoice window called WindowClosing and in the CancelClose event added WindowClosing = True, and then just added at the beginning of the method:

If WindowClosing then //Invoice was not modified
Return
End If

or in Window.Cancel close just stop the timer from running