Turnig off computer - event lazarus / 31-LCL ---------------------------------------------------------------------- Milsa · 2018-07-29 19:25 I am used FormDestroy. When I turn off computer, all applications close without violence. This event is not called. How can I detect turning off computer and close application with legal way? ---------------------------------------------------------------------- soerensen3 · 2018-07-29 20:51 Try OnCloseQuery. The shutdown will be delayed if you show a dialog like the save dialog. With the CanClose parameter you can even stop the shutdown. I didn't try it for a long time though and I think some OS's might kill the application in some cases. ---------------------------------------------------------------------- flowCRANE · 2018-07-29 21:10 When you shut down system, Windows sends WM_QUERYENDSESSION and WM_ENDSESSION messages – handle these message(s) and do what you must to do. Read this: WM_QUERYENDSESSION message. Some helpful informations: Should I process WM_ENDSESSION, WM_QUERYENDSESSION, both or neither?