Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A comment above suggested I summarize the answer I found <a href="http://www.esanu.name/delphi/Win%20API/Performing%20an%20action%20when%20Windows%20shuts%20down%20a%20Delphi%20app.html" rel="noreferrer">(link)</a>. Basically, it says to provide your own handler for WM_QUERYENDSESSION. This is the recommended code:</p> <pre><code>procedure TForm1.WMQueryEndSession(var Message: TWMQueryEndSession); begin inherited; { let the inherited message handler respond first } {--------------------------------------------------------------------} { at this point, you can either prevent windows from closing... } { Message.Result:=0; } {---------------------------or---------------------------------------} { just call the same cleanup procedure that you call in FormClose... } MyCleanUpProcedure; {--------------------------------------------------------------------} end; procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin MyCleanUpProcedure; end; </code></pre> <p>I am not sure that calling Inherited before calling MyCleanUpProcedure is completely correct. If the Inherited procedure responds back to Windows first, Windows could still shut down the application before MyCleanUpProcedure had completed. I am not sure what Inherited does for the <code>WM_QUERYENDSESSION</code> message - I assume it defaults to allowing the shutdown immediately. In my application, the MyCleanUpProcedure runs very fast, so it would not cause Windows to display the "Not Responding" dialog due to no response to the <code>WM_QUERYENDSESSION</code> message. </p> <p>To be sure my procedure runs to completion, maybe the procedure should look like this:</p> <pre><code>procedure TForm1.WMQueryEndSession(var Message: TWMQueryEndSession); begin MyCleanUpProcedure; inherited; end; </code></pre> <p>Or possibly this?</p> <pre><code>procedure TForm1.WMQueryEndSession(var Message: TWMQueryEndSession); begin MyCleanUpProcedure; Message.Result:=1; // tell Windows it is OK to shut down end; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload