Example 3: Reacting to a check box toggle

Uses OnCheckChange, which fires before a check box changes, to refuse a change that breaks a rule and to update a related field when the change is accepted.

Scenario

The boolean field Active is shown as a check box. A product that still has stock cannot be made inactive; when the box does change, the field UpdatedAt records the moment.

Units

Besides EgFireGrid: System.SysUtils (SameText, Abort, Now), FMX.DialogService (TDialogService) and the unit of the dataset component (here FireDAC.Comp.Client, for Query1).

The handler

procedure TForm1.Grid1CheckChange(Sender: TObject; Column: TEgFireGridColumn; RowIndex: Integer);
var
  WasActive: Boolean;
begin
  if not SameText(Column.FieldName, 'Active') then
    Exit;
  WasActive := Query1.FieldByName('Active').AsBoolean;
  if WasActive and (Query1.FieldByName('Stock').AsInteger > 0) then
  begin
    TDialogService.ShowMessage('A product with stock cannot be made inactive.');
    Abort;
  end;
  Query1.Edit;
  Query1.FieldByName('UpdatedAt').AsDateTime := Now;
end;

Why it works this way

See Also

(C) 2026 Easygate, Lda