How can I use code in a Windows Close event correctly?

I have code to save a value to the database in the Close Event of a window. But the problem is that this code ALWAYS runs when I close the app itself, which, obviously also closes that window. How can I avoid that the Close window code runs when I close the app?

What you’re looking for is the CancelClose event, not the Close event. The appQuitting boolean tells you whether the close has been initiated because the user is closing the window, or because the app is quitting.

Thanks. I placed the code inside the CancelClose event of the window. Running the app inside Xojo and closing the app from the .Debug menu, still runs the Cancel/close code from the Window.

Yes, but there’s a Boolean parameter named appQuitting that reflects whether or not the close is occurring because of the app quitting. You can make use of that in your code.

Ah, brilliant! Thanks! It’s working correctly now.

if appQuitting then
// only when the app is quitting ...

else
// only when the app is *not* quitting ...

end if

Thanks!