|
AnyDAC
|
Specifies record-level client constraints that must be met when editing the data.
Use Constraints to maintain record-level constraints for the dataset.
Record-level constraints force business ruless limiting few fields in a single record. This constraints are checked at end of data editing (Post / AppendRecord / InsertRecord). Constraints, limiting single field are field constraints and must specified at TField.CustomConstraint or TField.ImportedConstraint.
The Constraints checking is performed when ConstraintsEnabled is True. If application needs to perform large updates to the dataset and application can guarantee the data consistancy, then set ConstraintsEnabled to False before updates, and return to original value after updates. The constraints are not checked at data fetching.
The expressions in Constraints must be predicates, evaluating to Boolean value. AnyDAC supports expression syntax compatible with:
See Writing Expressions for details of how to write constraint expressions.
property Constraints;
ConstraintsEnabled, DisableConstraints, EnableConstraints, BeginBatch, EndBatch, TDataSet.Post, TDataSet.AppendRecord, TDataSet.InsertRecord, TField.CustomConstraint, TField.ImportedConstraint
with ADMemTable1.Constraints.Add do begin CustomConstraint := 'sal + bonus <= 2000'; ErrorMessage := 'The employee payments must be equal or less than 2000 usd'; end; ADMemTable1.ConstraintsEnabled := True; ADMemTable1.Edit; try ADMemTable1.FieldByName('sal').AsFloat := 1800; ADMemTable1.FieldByName('bonus').AsFloat := 300; // here exception will be raised ADMemTable1.Post; except ADMemTable1.Cancel; Application.HandleException(Self); end; ADMemTable1.ConstraintsEnabled := False; ADMemTable1.Edit; ADMemTable1.FieldByName('sal').AsFloat := 1800; ADMemTable1.FieldByName('bonus').AsFloat := 300; // here exception will be NOT raised, because constraint checking is disabled ADMemTable1.Post;
|
What do you think about this topic? Send feedback!
|