Skip to content

HowToDisableModel

Carlo Barazzetta edited this page Jan 27, 2017 · 2 revisions

How to enable/disable inserting, editing, deleting records

The following instructions apply to List Controllers.

Normally the function bar of a List Controller shows the following buttons:

AllButtons.png

if you set IsReadOnly: True at model level the standard "insert", "Edit" and "Delete" buttons will disappear in all List Controllers using that model.

In case you have different Views using the same Model and you want to allow different operations, then explicitly set the node Controller/GridPanelController in the view:

For example, you can allow just Viewing and Inserting records with the following code:

Type: Data
Controller: List
  GridPanelController:
    AllowViewing: True
    PreventDeleting: True
    PreventAdding: True
    PreventEditing: False

you will obtain the following situation:

ViewingEditing.png


In case you need to prevent editing or deleting for a specific record in accordance with some field values you have to:

  • define a Delphi rule by code in Rule.pas
  • add a Rules node in the model

Delphi Code: Inherit the EditRecord procedure, check data values and, in case, raise an exception.
Here is a simple example extracted from a real-world project:

type
  TMaintenanceEdit= class(TKRuleImpl)
  public
    procedure EditRecord(const ARecord: TKRecord); override;
  end; 
....
implementation
procedure TMaintenanceEdit.EditRecord(const ARecord: TKRecord);
begin
  inherited;
  if ARecord.FieldByName('STATUS').AsString = 'APPR' then
    RaiseError('You can''t modify an already approved maintenance');
end;

Node Rule

Rules:
  MaintenanceEdit:

Details record

In case of a master/detail form, you can enable/disable inserting, editing, deleting even for detail records. You have to specify AllowViewing, PreventDeleting, PreventAdding, PreventEditing subnodes for every detail in the DetailTables/Table/Controller node of the view.

Clone this wiki locally