Confirming delete of a record

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
captainrproton
Posts: 7
Joined: Tue 28 Nov 2006 18:49
Location: Narooma NSW Australia

Confirming delete of a record

Post by captainrproton » Wed 13 Dec 2006 09:30

Hi,

I have a dbnavigator on my form and I want to display a nicer confirmation window when deleting a record, or infact I want to offer a third alternative. Right now when you press the delete button a message pops up which says "Delete Record" Yes or No.

I want to option to cancel the delete but I can't seem to stop it. The delphi docs mention the abort procedure for tdataset, but the MyDac stuff doesn't have it. It does have Cancel which says it will stop updates.

My code is as follows;

if button=nbdelete then
begin
case messagedlg('Deleting a record removes it from the database.'+#13+#10+
'A deleted record is not available for historical records.'+#13+#10+#13+#10+
'Would you prefer to mark this company as "Inactive"?',mtconfirmation,[mbyes,mbno,mbcancel],0)
of
mryes:begin
contractortable.cancel;
contractortable.edit;
contractortable.FieldByName('CurrentStatus').AsString:='Inactive';
contractortable.Post;
end;
mrcancel:contractortable.cancel;
end;
end;

How can I stop the delete without using the built in confirmation. I have put this code into the beforedelete event and on the buttonclick event. But, the delete still goes ahead.

Craig

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Wed 13 Dec 2006 12:33

Try to move this code to BeforeDelete event handler. And replace the line:

Code: Select all

  mrcancel:contractortable.cancel; 
with the following one:

Code: Select all

  mrCancel: Abort; 
To prevent popping up the dialog box with the "Delete record?" message you should set the ConfirmDelete property of your TDBNavigator object to False.

captainrproton
Posts: 7
Joined: Tue 28 Nov 2006 18:49
Location: Narooma NSW Australia

Post by captainrproton » Thu 14 Dec 2006 19:35

Thanks, that did the trick.

I did have the code in the wrong event, stupid of me really.

It is now working, thanks heaps.

Craig

Post Reply