ComponentOne True DataControl 8.0
Field Constraints

A True DataControl field can have several constraints or none. Specifying constraints on the field level represents an important feature of True DataControl; it allows you to put application logic where it belongs – in your data source. Without it, Visual Basic programmers have to enforce field validation rules in event handlers in bound controls. Every VB programmer knows that this is inconvenient and error-prone.

Basically, a constraint is a Boolean expression. Field constraints are evaluated every time the field value is changed, for whatever reason. If a constraint is not satisfied, that causes a constraint violation error and cancels the field modification.

Each constraint has a constraint expression that is the constraint itself, an applicability condition expression that specifies whether the constraint should be imposed, and a message expression that gives the error message if the constraint is not satisfied. For example, a field CustomerID can have the following constraint (in pseudo-code notation, as it appears in the Fields property page):

Example Title
Copy Code
if (CheckCustID) Len(CustomerID)<=5

This line means that CustomerID cannot exceed five characters.

Here CheckCustID (it can be a parameter name) is the applicability condition expression. The constraint is enforced only if it evaluates to True. The applicability condition is optional. If it is empty, the constraint is always enforced.

Field constraints form the Constraints collection, a property of the Field object that is accessed via the Constraints property. Each constraint in this collection is represented by a Constraint object, which is indexed by its zero-based ordinal position in the collection.

At design time, field constraints can be created in the Fields property page (pressing the New button or selecting New Constraint from the context menu). At run time, you can create them using the Add method of the Constraints collection. Bear in mind, that, unless you do it in the WillOpenData event, that will cause refresh of the TData control.

Following is the list of constraint properties:

ConstraintExpression

Specifies a Boolean expression that determines the validity of a modified field. If the constraint expression evaluates to False, the modification will be canceled and the user will be notified of the constraint violation according to the MessageExpression property.

ConditionExpression

Specifies an optional Boolean expression controlling the applicability of the constraint. If this expression is not empty and evaluates to False, the entire constraint will be ignored.

MessageExpression

Specifies a string expression that determines the error message to be displayed when a constraint violation occurs. If you leave this property blank, True DataControl displays a generic "Constraint violation" message.

 

 


Copyright (c) GrapeCity, inc. All rights reserved.

Product Support Forum  |  Documentation Feedback