Skip to content

HowToDisableModel

iraichi edited this page Apr 24, 2015 · 18 revisions

How enable/disable inserting, editing, deleting for 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 Controller using that model.

In case you have different Views using the same Model and you want to allow different operations, than 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 fields' values you have to write Delphi code in Rule.pas. Inherit the EditRecord procedure, check data values and, in case raise an exception as in the following example:

type
  TRecordEdit = class(TKRuleImpl)
  public
    procedure EditRecord(const ARecord: TKRecord); override;
  end; 
....
implementation
procedure TRecordEdit.EditRecord(const ARecord: TKRecord);
begin
  inherited;
  if ARecord.FieldByName('STATUS').AsString = 'APPR' then
    RaiseError(_('Status = 'APPR' - You can't edit record)');
end;

Remember to regist the rule and to create the rule node in the Model:

Rules:
  TRecordEdit:

Clone this wiki locally