mierlp Posted January 24, 2013 Posted January 24, 2013 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 Quote
Oliver Morsch Posted January 24, 2013 Posted January 24, 2013 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") Quote
mierlp Posted January 24, 2013 Author Posted January 24, 2013 Hi Oliver, I don't understand where/how to set the ''Set Action :=caNone'' option, can you explain? Regards Peter Quote
Oliver Morsch Posted January 24, 2013 Posted January 24, 2013 I don't understand where/how to set the ''Set Action :=caNone'' option, can you explain? procedure TFormProduct.UniFormClose(Sender: TObject; var Action: TCloseAction); Do you see the (var) "action"? Quote
mierlp Posted January 24, 2013 Author Posted January 24, 2013 Hi Oliver Yes i see it but maybe i'm total stare me blinded but don't see what to change into caNone ...maybe it's time for weekend Quote
Oliver Morsch Posted January 24, 2013 Posted January 24, 2013 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... Quote
mierlp Posted January 24, 2013 Author Posted January 24, 2013 Oliver Many...many thanks for you help... this works and just what i needed. Welll..i should say...if you're around...be drink a beer together Thanks again Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.