Link to home
Start Free TrialLog in
Avatar of filipecorreia
filipecorreiaFlag for Portugal

asked on

Saving data when application exits

the aim is to save (to file) some data when the application exits.
 I want this to happen even if windows terminates the app when
 windows is shutdown. Perhaps I could catch the quit message sent
 to the app but I don't have any idea on how to do that.



   Thanks in advance

         Filipe Correia
ASKER CERTIFIED SOLUTION
Avatar of kretzschmar
kretzschmar
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of filipecorreia

ASKER

but... is the form's OnClose event trigered in case the main form is always hiden (by doing Application.ShowMainForm:=false) ? I think it isn't because when I put ShowMessage("hey"); in the OnClose event no message is shown when the app exits.


  Filipe Correia
not the OnClose-event,
the OnCloseQuery-Event is meant

;-)
Avatar of lucika
lucika

If windows terminates the app when windows is shutdown app there comes the message WM_QUERYENDSESSION
But even in the case of a windows shutdown the OnCloseQuery event should still be fired - Kretzschmar is correct.

GL
Mike
Also, I was reading a few of the TI's on Borland's website the other day and they stated that if you do have a handler for the OnCloseQuery and set the value of CanClose to False, Windows shutdown can be halted.
I'd put my code in the OnDestroy event handler.
It's sure to get called there, whatever the reason for
termination.

rondi
I have an option in my app that terminates the app by doing:

      Application.Terminate()

When I do that the OnCloseQuery isn't trigered.
To solve this I tried subtitute this code by:

        Form1->Close();

and now everything seems to be working fine(I'll test it some more times).

Do you predict any sort of problem that may hapen by doing this?



rondi: I will try your suggestion but I haven't tried it yet.


    Filipe Correia
I suggest to use the Close, rather than Terminate or HALT - as these are not polite ways to end your application !
Hi

rondi: An EAccessViolation happens if I use the OnDestroy event. I don't know why!

I'll use the onCloseQuery event. My app seems to be working ok until now.


  Thanks to you all

        Filipe Correia