Jump to content

Message when closing form


mierlp

Recommended Posts

Hi

 

I have a form including a dbnavigator for editing product. When the user closes the form the OnClose events is fired

with the following code. There's a check if the database is in edit or insert mode and if...then fire the message

for saving or canceling the changes.

 

procedure TFormProduct.UniFormClose(Sender: TObject; var Action: TCloseAction);
begin
 if dmMain.Product.State in [dsEdit,dsInsert] then begin
    MessageDlg('Information has been changed but not saved' + '<br/><br/>' + 'Would you like to save the changes (Y/N) ?', mtConfirmation, mbYesNo, QuestionSaveYesNo);
 end;
end;

 

This uses the following Callback code :

 

procedure TFormProduct.QuestionSaveYesNo(Res: Integer);
begin
 case Res of
   mrYes : dmMain.Product.Post;
   mrNo  : dmMain.Product.CancelUpdates;
 end;
end;

 

This should do the trick (normally in vlc it does) but for some reason it doesn't cancel the changes

and the changes are always saved.

 

A other behavior is that the form is already close and only the question is on the screen, normally

both have to be on screen...maybe it's a behavior of EXT JS ?

 

How to modify it so that the form is still on screen including the message (is Onclose the wrong event?)

and the changes are canceld.

 

I still use 0.89 because of the uniEdit desing height issue...which i don'nt know if it's already solved?

 

Regards Peter

Link to comment
Share on other sites

A other behavior is that the form is already close and only the question is on the screen, normally

both have to be on screen...maybe it's a behavior of EXT JS ?

 

Set Action := caNone before (when) you call MessageDlg. In "TFormProduct.QuestionSaveYesNo" you must call Close again (or do nothing in the last case if you ask "YES/NO/CANCEL")

Link to comment
Share on other sites

procedure TFormProduct.UniFormClose(Sender: TObject; var Action: TCloseAction);
begin
  if dmMain.Product.State in [dsEdit,dsInsert] then begin
     Action := caNone;
     MessageDlg('Would you like to save the changes (Y/N/C) ?', mtConfirmation, mbYesNoCancel, QuestionSaveYesNo);
  end;
end;

procedure TFormProduct.QuestionSaveYesNo(Res: Integer);
begin
  case Res of
    mrYes : dmMain.Product.Post;
    mrNo : dmMain.Product.CancelUpdates;
  else 
    EXIT;
  end;
  Close;
end;

 

Try this code, but it is not tested...

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...