简体   繁体   中英

Data validation in Delphi using TField.CustomConstraint

I'm using Delphi 6XE, with MySQL as database server.

I have table's fields as shown below

在此处输入图片说明

I'm using FireDAC.

在此处输入图片说明

I'm trying to implement data validation using TField.CustomConstraint , so I use the Field Editor to generate TField descendant objects as shown below

在此处输入图片说明

I have setup field's property using Object Inspector

With browsing from Google, and documentation, the authers give example to use like CustomConstraint := 'x>1000'; I tried with x but all data were not displayed when running the program, so I switched to use field name instead. But anyway I still can input any data I want, no validations were applied at all.

在此处输入图片说明

Please advise how to setup data validation in Delphi. Thanks.

Set the ConstraintsEnabled property of your FDQuery1 component to True. The reference says the following about this property:

Specifies whether the dataset performs constraint checking.

Use ConstraintsEnabled to get or set the flag that controls the automatic record-level constraints enforcement. When ConstraintsEnabled is False (the default), the dataset does not check Constraints. This allows the dataset to perform large data updates without the overhead of checking constraints. When ConstraintsEnabled is True, the dataset checks Constraints at the end of data editing (Post / AppendRecord / InsertRecord).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM