How to prevent deletion on a non-modal platform?

  

You do this in a Delphi VCL application, to give the user an opportunity to stop a record delete from occurring:

procedure TMyDataModule.CDSDataBeforeDelete(DataSet: TDataSet);
begin
if MessageDlg(‘Are you sure you want to delete this line?’,
mtWarning, [mbYes, mbNo], 0) <> mrYes then
SysUtils.Abort
end;

But in a non-modal environment, like FMX on Android (eg. from a ListView with CanSwipeDelete = True), this won’t work because the execution continues before the user has a chance to answer the question.
My Listview is livebound(?) to the CDSData (* => Synch). I am doing this in Listview.DeletingItem event handler, which even though it is bound doesn’t call the CDSData’s onBeforeDelete event handler. (not that that helps either way).

procedure TfrmMain.ListView1DeletingItem(Sender: TObject; AIndex: Integer;
var ACanDelete: Boolean);
begin

FMX.DialogService.TDialogService.MessageDialog(
‘Delete this entry from your list?’,
TMsgDlgType.mtConfirmation, [TMsgDlgBtn.mbNo, TMsgDlgBtn.mbYes],
TMsgDlgBtn.mbNo,
0,
procedure (const AResult: TModalResult)
begin
if AResult = System.UITypes.mrYes then
ACanDelete := True
else
ACanDelete := False;
end
);

// doesn’t call the beforedelete of the CDS
// ClientModule2.CDSData.Delete;

end;

Comments are closed.