Having trouble with a desktop app. Closing on Windows via the ‘X’ closes the main window (or at least appears to) fine - have confirmed code in the Closing event gets called and executed successfully but the application just hangs after that code has completed (but not all the time)****. The app is very simple - main window and 3 other windows. I have ensured that the other windows get closed explicitly in the Closing event of the main window but still no dice.
Hitting ‘Pause’ after code in the Closing event has been executed shows that there appears to still be a window open but I really cannot track down what it is:
Closing a window doesn’t usually make an app quit. I assume there’s a place in your code where the user can tell the app to quit, put Quit in that code, that tells the app to quit. Look up Quit in the Xojo documentation for more info,.
Add a property to each window and in the Open event of each, assign a unique value to the property. Either the window type name or an integer, anything that will help you identify what kind of window is being left behind.
Thanks all. I am using the Quit method in the main window closing right now and so far so good. Closing of the app seems to mostly take a lot of time but that may be unrelated and I believe more related to the browser based controls that I’m using and their closure…
Up to about 30 or so starts and quits via main window ‘X’ and seems to be working. Thanks @John_McKernon . As I mentioned, I was closing all of my windows (app DesktopWindows) explicitly in this event but occasionally whatever window this is would hang around and prevent the app from closing.
Like I say, so far so good and will do more tests tomorrow. Feels unnatural that my explicitly closing all windows like this doesn’t always close the app but that seems to be the case.
A window which has closed, but not destructed. This can be caused when you have a reference to a Window (or possibly to a control inside the window) that is not nil, when you close the window. This can happen internally (e.g. a property inside the window is pointing to one of the window controls) or externally (e.g. Window2 has a property which points to Window1, or an App property)
A window which was closing, but during or after the close process, re-opened because of ImplicitInstance=true.
As Mike D said, closing the window does not necessarily destruct it and remove it from the list of windows. If you have a reference to the window still lingering, you wind up with a zombie window like you’re describing.
That can be infuriating. I always like to say the difference between a surgeon and a programmer is the surgeon does everything he can to keep the patient alive, where the programmer wants to kill the patient over and over until he sees the pattern. Intermittent errors are the worst!