Skip to content

HowToCheck

Carlo Barazzetta edited this page Jan 27, 2017 · 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