Phxtecno Posted December 17, 2015 Share Posted December 17, 2015 Hello, I have a DbNavigator with Delete button enabled and Confirm Delete disabled, because I need a custom message on Delete. So I have put this code in the onBeforeDelete event of the DataSet: procedure TformCustomers.tabCompositionBeforeDelete(DataSet: TDataSet);begin // Ask confirm MessageDlg('Confirm Delete of item: '+ tabComposition.FieldByName('TABLECODE').AsString +' ?', mtConfirmation, mbYesNo, procedure(Sender: TComponent; Res: Integer) begin if Res <> mrYes then // Annulla delete Abort; end//procedure );//MessageDlgend; But the records get deleted before my answer... Can you help ? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted December 17, 2015 Share Posted December 17, 2015 Hi, While, try: procedure TMainForm.ClientDataSet1BeforeDelete(DataSet: TDataSet); begin ClientDataSet1.BeforeDelete := nil; MessageDlg('Confirm Delete of item: ?', mtConfirmation, mbYesNo, procedure(Sender: TComponent; Res: Integer) begin if Res = mrYes then begin ClientDataSet1.Delete; end; ClientDataSet1.BeforeDelete := ClientDataSet1BeforeDelete; end ); Abort; end; Best regards. Quote Link to comment Share on other sites More sharing options...
Phxtecno Posted December 17, 2015 Author Share Posted December 17, 2015 Thank you ! it works, but seems a "dirty" solution detach the event in this way... Is there a cleaner way to deal with this kind of situations ? Regards, Marc 1 Quote Link to comment Share on other sites More sharing options...
Administrators Farshad Mohajeri Posted November 17, 2020 Administrators Share Posted November 17, 2020 This one is more clean: procedure TMainForm.UniDBNavigator1BeforeAction(Sender: TObject; Button: TNavigateBtn); begin if Button = nbDelete then begin MessageDlg('Confirm?', mtConfirmation, mbYesNoCancel, procedure(Sender: TComponent; Ans: Integer) begin if Ans = mrYes then begin DataSource1.DataSet.Delete; end; end ); Abort; end; end; Quote Link to comment Share on other sites More sharing options...
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.