Tclientdataset [27]: Field Value constraint (or input restriction)

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.