Doing things in OnCloseQuery
is executing them in the same thread as you would as in finalization
. I don’t think you achieve anything by doing things in OnCloseQuery
versus in “finalization
after making sure that views have stopped by Application.MainWindow.Container.View := nil
”.
And since OnCloseQuery
is not going to run always when window is closed by explicit Window.Close
( Where to intercept closing application? - #3 by michalis ), it’s still not the best place to make “cleanup that must be executed always”
I realize that things are difficult when using threads, and client/server, but this doesn’t change the above recommendation.
-
If you have threads, you must cleanup the data correctly.
-
If you client/server in threads, you may need to also wait for those threads.
-
I realize it’s not easy (and why Indy can make either memory leaks or crashes, as documented in 3.4. Note: There are known memory leaks when using Indy).
-
Still, if you want to make a “cleanup that always executes”, doing it in
Stop
of the view is what I recommend. This is our equivalent ofOnBeforeClose
callback that you mention.And then if you need to do some “global cleanup” in some
finalization
, that depends that views are stopped, do it after callingApplication.MainWindow.Container.View := nil
– as this makes sure that all views are stopped. This will work regardless of how the window got closed (by Alt+F4, byWindow.Close
, byApplication.Terminate
etc.).