Mike,
but ON SHUTDOWN also happens, when the OS shuts down. And you usually don't want to be in the way there.
gbcpastor,
there are problems with the _screen closebox X, wherever you want to do end-of-business-day processing which a) should
run once per day and b) should run
once per day. I prefer ON SHUTDOWN QUIT (don't think that leaves no spare room for the application to tidy up, all classes run their Destroy event, all forms get a QueryUnload besides their Destroy and Unload).
Part of the solution for such a condition is not trying to avoid any unwanted exit, but do a countermeasure at startup, detecting whether the application was ended normally and even if so, whether the user did pick the end-of-business-day processing or not, to do it then. That detection is easy, you write out a file at the end of a normal closing of your application, check its existence at startup. When it exists you remove it and any unplanned closing leaves this state as detectable non-normal end of the previous session, you only generate it again at the normal ending. Same about the end-of-day-processing, you have several ways to also mark that in some data, especially if its sufficient the last system of a shop triggers that you want that information centralized and not in a local file existence, only.
You gotta be prepared for the case an app crashes anyway. And that can happen, no matter how pristine your code may be, due to disc space running full, power outages and more.
You can anyway remove that X option or even the whole title bar for the user for sake of running as the main software like a POS system, and still have ON SHUTDOWN QUIT to not be in the way when the OS restarts. which may also be due to Windows updates.
If you simply try Mikes routine and shut down your system, the mechanism of Windows listing software not closing will bring up your application and ask to cancel the system shutdown. From that perspective, you're good to go with such code, as long as the user is there to react, but the option has a timeout and when this happens during night the OS will still simply kill your process. Another reason you'd want to be prepared for the scenario a previous ending of your application wasn't as planned.
Bye, Olaf.
Olaf Doschke Software Engineering