Board index » delphi » Handling "Exit Windows" when user "forgets" to close application

Handling "Exit Windows" when user "forgets" to close application

Imagine this one. Customer wants to go home. Screen says:

   "It is now safe to turn off your computer."

Next morning, customer phones. Database not working.

Delphi apps do not process OnClose() when the user shuts Windows 3.1
down. Databases not closed can corrupt.

Solution:

Procedure TMyForm1.MyWindowsQuitter(var MyMess: TMessage);
begin
    inherited; {this calls OnCloseQuery}
    close;      {this calls OnClose}
end;

Under PRIVATE:

Procedure MyWindowsQuitter(var MyMess: TMessage);
              message WM_QUERYENDSESSION;

That's it.

Email appreciated. I respond to every email.
Matthew

 

Re:Handling "Exit Windows" when user "forgets" to close application


Quote
Matthew wrote:

> Imagine this one. Customer wants to go home. Screen says:

>    "It is now safe to turn off your computer."

> Next morning, customer phones. Database not working.

> Delphi apps do not process OnClose() when the user shuts Windows 3.1
> down. Databases not closed can corrupt.

Here you go. Don't forget that once you've completed your shut down you
must pass on the message....

- declare the proc as protected in your main form's class def.
- message constants and associated messages are defined in messages.pas
(for reference)

- this code is taken almost verbatim from Delphi Unleashed 2

procedure TMainForm.WndProc(var Msg: TMessage);
 Var processmessage : boolean;
begin
  if Msg.Msg = WM_QUERYENDSESSION then ProcessMessage := False;
  if ProcessMessage then
  inherited WndProc(Msg)
  else
   begin
    {database maintenance routines}
    inherited WndProc(WM_QUERYENDSESSION);
   end;
end;

Quote

> Solution:

> Procedure TMyForm1.MyWindowsQuitter(var MyMess: TMessage);
> begin
>     inherited; {this calls OnCloseQuery}
>     close;      {this calls OnClose}
> end;

> Under PRIVATE:

> Procedure MyWindowsQuitter(var MyMess: TMessage);
>               message WM_QUERYENDSESSION;

> That's it.

> Email appreciated. I respond to every email.
> Matthew

Other Threads