Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Delphi and Windows Log Off

149 views
Skip to first unread message

Pat Rundle

unread,
Jun 10, 2002, 4:36:43 AM6/10/02
to
I have written a database program in Delphi(5) which performs some
action on program exit.

Some users of the program log-off windows without exiting the program.
If they do this the program closes but the action (placed in main form
OnClose or OnDestroy) does not happen.

Any ideas anyone?

Pat

Michael Davis

unread,
Jun 10, 2002, 3:34:23 PM6/10/02
to
pat.r...@opsysdisplays.com (Pat Rundle) wrote in message news:<d4d6aded.02061...@posting.google.com>...

Pat,

This is a common problem in Delphi. Some people regard it
as a bug in Delphi, but I think it is better regarded as a debatable
design decision. There are actually pros as well as cons.

When Windows is about to shut down it sends a "WM_EndSession"
message to all running applications so that they can do any
last minute shut down tasks. Delphi does not automatically
put a message handler into your application to deal with this
message: it is up to you to put a message handler in if you need one.

I don't know whether you know all about message handling or not,
but in case you don't:

In the private section of your main form put this definition:

procedure WMEndSession(var Msg : TWMEndSession); message WM_ENDSESSION;

and then in the implementation put in a procedure something like this:

procedure TForm1.WMEndSession(var Msg : TWMEndSession);
var CloseAction : TCloseAction;
begin
if Msg.EndSession = TRUE then
CloseAction:=caFree;
FormClose(Self, CloseAction); //Or whatever procedure you want
//called on shut down.
inherited;
end;

I hope this is of some help.
Michael Davis

Evgeny V. Levashov

unread,
Jun 10, 2002, 9:10:42 AM6/10/02
to
Hi there.

Read about WM_QUERYENDSESSION message on the help. If you don't want Windows
session to be closed, your application should return zero when it gets this
message.

PS. I wonder, I have answered to the same question second time today in
different NGs.


"Pat Rundle" <pat.r...@opsysdisplays.com> ???????/???????? ? ????????
?????????: news:d4d6aded.02061...@posting.google.com...

Pat Rundle

unread,
Jun 11, 2002, 5:03:20 AM6/11/02
to
Thanks Michael, now working correctly.

Pat

miki...@yahoo.co.uk (Michael Davis) wrote in message news:<62f60a1.02061...@posting.google.com>...

0 new messages