FireDAC.Comp.DataSet.TFDDataSet.Constraints
Delphi
property Constraints: TCheckConstraints read FConstraints write SetConstraints stored IsCS;
C++
__property Constraints = {stored=IsCS};
Contents
Properties
Type | Visibility | Source | Unit | Parent |
---|---|---|---|---|
property | public | FireDAC.Comp.DataSet.pas FireDAC.Comp.DataSet.hpp |
FireDAC.Comp.DataSet | TFDDataSet |
Description
Use Constraints to maintain record-level constraints for the dataset.
Record-level constraints force business rules by limiting only a few fields in a single record. The Constraints are checked at the end of the data editing by using the Post, AppendRecord, or InsertRecord method. Constraints that limit the value of a single field can be specified using the CustomConstraint or ImportedConstraint property.
The Constraints are applied only if they are defined before opening the table.
The Constraints checking is performed when the ConstraintsEnabled property is True. Set the ConstraintsEnabled property to False if the application needs to perform large updates to the dataset and the application can guarantee the data consistency. You can return to the original value after the updates are done. The Constraints are not checked at data fetching.
The expressions in the Constraints have to be predicates, which are evaluated as Boolean values. FireDAC supports an expression syntax compatible with:
- Client dataset;
- Oracle 8 (not for 100%).
See Writing Expressions for details on the expression syntax.
Example
with FDQuery1.Constraints.Add do begin
CustomConstraint:='sal + bonus <= 2000';
ErrorMessage:='The employee payments must be equal or less than 2000 usd';
end;
FDQuery1.ConstraintsEnabled:=true;
FDQuery1.Open();
//open the query after the Constraints were defined
try
FDQuery1.FieldByName('sal').AsFloat := 1800;
FDQuery1.FieldByName('bonus').AsFloat := 300;
FDQuery1.Post;
except
FDQuery1.Cancel;
Application.HandleException(Self);
end;