Skip to content
This repository was archived by the owner on Nov 3, 2026. It is now read-only.

HowToCheck

Carlo Barazzetta edited this page Oct 28, 2021 · 1 revision

How to validate data before storing

If you want to operate a validation check before storing data in the database, you have to:

  • declare and write a rule for the model in Delphi rule.pas unit
  • define the node Rules: for the model

example form HelloKitto:

# rule.pas
type
  TCheckDuplicateInvitations = class(TKRuleImpl)
  public
    procedure BeforeAdd(const ARecord: TKRecord); override;
  end;

procedure TCheckDuplicateInvitations.BeforeAdd(const ARecord: TKRecord);
begin
  if ARecord.Store.Count('INVITEE_ID', ARecord.FieldByName('INVITEE_ID').Value) > 1 then
    RaiseError(_('Cannot invite the same girl twice.'));
end;
# model Invitation.yaml
ModelName: Invitation
Fields:
.....
Rules:
  CheckDuplicateInvitations:

Clone this wiki locally