Disable editing of Firedac dataset without generating an exception

Asked

Viewed 263 times

2

Suppose a FDQuery with a select simple be connected with a DBGrid.

I want to prevent the user from making any edits to the registry.
I know there’s a choice EnableDelete in the FDQuery, but if the user tries to delete the record, for example, the FireDAC will generate an exception.

You can prevent Editing/Inserting/Deleting without generating an exception?

This control cannot be done on DBGrid, has to be done in the Dataset.

More details:

  • Delphi XE7
  • Firebird 2.5
  • I want to make a generic solution because I have this problem in several screens and have use the FDQuery in a inherited component, apply the solution in this inherited component would solve my problem in all the screens of the system.
  • Which exception is being triggered when the user tries to delete in DBGrid?

  • @Celsomarigojr The native exception of Firedac: [Firedac][Comp][DS]-215. Record deleting for dataset [Query1] is disabled.

  • @Celsomarigojr I edited the question....

  • In this case you would also have to inherit the DBGrid then you would make the configuration of ReadOnly only once too?

  • I agree with you that would be a good solution, but I can not change all dbgrid´s of my system at this time. The solution needs to be applied in Dataset (FDQuery). @Celsomarigojr

2 answers

2

You can try to leave your DBGrid as ReadOnly, see if this property exists in your Delphi. Which Delphi is using?

Maybe that’ll fix it:

With DBGrid1
.AllowAddNew = False
.AllowDelete = False
.AllowUpdate = False
End With

If none of this works, schedule the event OnKeyPress or OnKeyDown to ignore any key.

  • I appreciate your help, but although functional is not quite what I’m looking for, see the issue I asked in my question please.

1


Replaces the event DoBeforeDelete of FDQuery.
At this event, I check the property EnableDelete is unchecked and if so, I only execute the command Abort.
It may sound a little extreme, but it does the same thing as Firedac, but without generating an exception for the user.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.