Board index » delphi » Newbie: Saving DB info when windows closes!!

Newbie: Saving DB info when windows closes!!

Using: Delphi 1, single user app using local Paradox thru IDAPI, TDatabase

The system I'm building is for real newbies -- they'll often close
windows without closing my app.  

So all DB inserts/changes are lost...
Very Bad...

I threw in this:

procedure Tf_Main.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  if not permitclose then
  begin
    show;
    messagedlg('Your Custom Application is still running!'+#10#13+      
      'Please exit before closing windows.',      
       mtInformation,[mbOK],0);    
    CanClose := false;  
  end;
end;

(I set permitclose to true if the exit button is pressed.)

Problem: focus is on main form even if the app has a modal form.
(Having a form highlighted when you can't do a thing with it is
very bizarre...)

Is there a way to tell which (If any) of my apps forms is modal,
and focus on that one?

ON THE OTHER HAND:
==================
Is there a way to save all database changes before the app closes?
I do have posts, uh, all over, all ready, but the changes don't
seem to be permanent outside of my app (ie app destroyed = changes lost)

I tried adding a Database.close in the main form's destroy event,
but it didn't seem to work...

So is there a way to do that?

Many thanks,

===================================================================
Norman Lange    |
Toronto, Canada | Just a little bit of knowledge is a scary thing...

 

Re:Newbie: Saving DB info when windows closes!!


Quote
Norman Lange wrote:

<snip>

Quote
> Is there a way to save all database changes before the app closes?

Norm,

Have you tried something like this.  It seems to work for me (or at
least I hope it does...)  It goes in the main form's Close event:

  if (Table1.State = dsEdit) then
    Table1.Post

Of course, you'll need to do one of the above for each table that can be
editted.

HTH,

-Mike

Re:Newbie: Saving DB info when windows closes!!


attach the following code to the Application.OnIdle event

DbiUseIdleTime;

One that is more reliable is DbiSaveChanges(TTable.Handle), to be applied
to all tables on all forms.

Check this message for more info. LOSING PARADOX/DBASE DATA???

Other Threads