Required, precision, maxvalue, minvalue:
Begin {required: required field} with tintegerfield. create (Self) Do begin fieldname: = 'id'; required: = true; Dataset: = clientdataset1; end; {precision: floating point Precision} with tfloatfield. create (Self) Do begin fieldname: = 'float'; precision: = 3; {for example, if the input is 1.2345, only 1.23} Dataset: = clientdataset1; end; {maxvalue, minvalue} with tintegerfield. create (Self) Do begin fieldname: = 'integer'; minvalue: = 1; maxvalue: = 99; Dataset: = clientdataset1; end; clientdataset1.createdataset; end;
You can specify constraints According to SQL syntax in the customconstraint attribute of a field;
Use the constrainterrormessage attribute of the field to specify the error message that violates the rule.
Procedure tform1.formcreate (Sender: tobject); begin with tintegerfield. Create (Self) Do begin fieldname: = 'id'; customconstraint: = 'x> 0 and X
Use the constraints attribute of the dataset to redo the preceding example:
Procedure tform1.formcreate (Sender: tobject); begin with clientdataset1.fielddefs do begin add ('id', ftinteger); add ('name', ftstring, 11); add ('sex ', ftstring, 2); add ('email ', ftstring, 21); end; with clientdataset1.constraints. add do begin customconstraint: = 'id> 0 and ID
The constraints of the dataset and the customconstraint of the field can also be completed during design.
However, constrainterrormessage and errormessage have bugs in the current version (14.0.3593.25826;
I tested it in Delphi 2007. No problem.