Skip to content

HowToCheck

iraichi edited this page Apr 24, 2015 · 6 revisions

How to validate data before storing

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

  1. define a rule for the model in Delphi rule.pas unit
  2. implement 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 Inviattion.yalm
ModelName: Invitation
Fields:
.....
Rules:
  CheckDuplicateInvitations:

Clone this wiki locally