Disable FireDAC dataset editing without generating exception

2

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

I want to prevent the user from doing any editing in the registry. I know there is a EnableDelete option in FDQuery , but if the user tries to delete the record, for example, FireDAC will generate an exception. Can you prevent editing / insertion / deletion without generating an exception?

This control can not be done in DBGrid , it must be done in Dataset .

More details:

  • Delphi XE7
  • Firebird 2.5
  • I want to make a generic solution because I have this problem in multiple screens and I use FDQuery in a legacy component , apply the solution in this legacy component would solve my problem in all the system screens.
asked by anonymous 20.09.2016 / 20:12

2 answers

1

Overrides event DoBeforeDelete of FDQuery . In this event, I check if the EnableDelete property is unchecked and if it is, I just run the Abort command. It may seem a bit radical, but it does the same thing as FireDAC , but without generating an exception for the user.

    
29.09.2016 / 14:01
2

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

Maybe this will solve:

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

If this does not work, set the event OnKeyPress or OnKeyDown to ignore any key.

    
20.09.2016 / 20:32