?
Solved

Saving data when application exits

Posted on 2001-09-14
10
Medium Priority
?
239 Views
Last Modified: 2010-04-06
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
0
Comment
Question by:filipecorreia
[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
10 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 180 total points
ID: 6483918
just assign a procedure to the onclosequery-event of your (main)-form,
where you can check, save or abort like

procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
var mresult : Integer;
begin
  if memo1.Modified then
  begin
    mResult := MessageBox(self.Handle,'Save before Quit?','Confirm',MB_YESNOCANCEL or MB_ICONQUESTION);
    case mResult of
      mrYes : If savedialog1.execute then
                memo1.lines.savetofile(savedialog1.filename);
      mrCancel : CanClose := False;
    end;
  end;
end;

meikl ;-)
0
 
LVL 1

Author Comment

by:filipecorreia
ID: 6484623
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
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6484650
not the OnClose-event,
the OnCloseQuery-Event is meant

;-)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 2

Expert Comment

by:lucika
ID: 6484892
If windows terminates the app when windows is shutdown app there comes the message WM_QUERYENDSESSION
0
 
LVL 6

Expert Comment

by:edey
ID: 6485012
But even in the case of a windows shutdown the OnCloseQuery event should still be fired - Kretzschmar is correct.

GL
Mike
0
 
LVL 1

Expert Comment

by:malsoft
ID: 6485912
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.
0
 
LVL 3

Expert Comment

by:rondi
ID: 6486732
I'd put my code in the OnDestroy event handler.
It's sure to get called there, whatever the reason for
termination.

rondi
0
 
LVL 1

Author Comment

by:filipecorreia
ID: 6490613
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
0
 
LVL 1

Expert Comment

by:DelRunner
ID: 6494844
I suggest to use the Close, rather than Terminate or HALT - as these are not polite ways to end your application !
0
 
LVL 1

Author Comment

by:filipecorreia
ID: 6499209
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
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month9 days, 16 hours left to enroll

762 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