Page 1 of 1

Confirming delete of a record

Posted: Wed 13 Dec 2006 09:30
by captainrproton
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

Posted: Wed 13 Dec 2006 12:33
by Antaeus
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.

Posted: Thu 14 Dec 2006 19:35
by captainrproton
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