Solved

Program Onclosing.

Posted on 2003-11-07
3
146 Views
Last Modified: 2010-05-18
Hey.

The program onclose event works when i close the program.
But when windows closes it or taskmanager then it won't use the onclose event.
How can you set an event on windows closes or taskmanager.

Thanks.
0
Comment
Question by:JuiceJJ
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 17

Accepted Solution

by:
geobul earned 125 total points
ID: 9701960
Hi,

About Windows shutdown:

type
  TForm1 = class(TForm)
  private
    { Private declarations }
    procedure WMQueryEndSession (var Message: TMessage); message WM_QUERYENDSESSION ;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.WMQueryEndSession(var Message: TMessage);
begin
  // do your stuff here
  Message.Result := Integer(true);
end;

Regards, Geo
0
 
LVL 17

Expert Comment

by:geobul
ID: 9701993
Forgot to say that TForm1 is your main form. The code above is for your main form only.

When I close an app with the Task manager (Windows XP) then my form's OnClose event gets called.

Regards, Geo
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 9702152
why don't use the OnCloseQuery event?
It's called when message WMQueryEndSession is received by the form...
and there you can also reject the closure setting canclose to false

F68 ;-)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question