ComponentOne True DataControl 8.0
Field Range Conditions

Using range conditions is an effective way to restrict a True DataControl recordset so that it only includes records where the field value is equal to a certain value or satisfies a certain condition. It is especially useful in defining Master-Detail Relationships between TData controls. However, range conditions can be used in many other situations, wherever it is necessary to restrict the recordset by known field values. For example, they are useful in creating forms allowing the end-user to restrict field values – a common task illustrated in Tutorial 8.

Field range conditions are unavailable in True DataControl Lite.

A True DataControl field can have several range conditions, or none. Each range condition has a comparison operation, a value expression, and an applicability condition expression. For example, a field LastName can have the following range condition (in pseudo-code notation, as it appears in the Fields property page):

Example Title
Copy Code
if (LastNameIsRestricted) LastName = LastNameValue

Here LastNameValue (it can be a parameter name) is the value expression. It evaluates to the value to which the LastName field is restricted. LastNameIsRestricted (it can also be a True DataControl parameter) is the Boolean condition (applicability expression). The range condition is applied only if it evaluates to True. Comparison operation here is = (“equals”).

Applicability condition expression is optional. If it is empty, the range condition always applies, as in the following example:

Example Title
Copy Code
LastName = “Bach”

Wherever possible, try to use range conditions for restricting True DataControl recordsets. Although the same result can be achieved with Filters, filters are usually much slower. Using filters, True DataControl fetches all records and tests every fetched record for the filter conditions, which involves much more fetches than using range conditions, which are optimized for better performance. In most cases, using range conditions has the same performance cost as WHERE conditions in SQL query.

Range conditions of a True DataControl field form the RangeConditions collection, a property of the Field object. Each range condition is represented by a RangeCondition object, an item of the RangeConditions collection, indexed by its zero-based ordinal position in the collection.

At design time, range conditions can be created in the Fields property page (pressing the New button or selecting New Range Condition from the context menu). At run time, you can create them using the Add method of the RangeConditions 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 range condition properties:

ComparisonOperation

Specifies the type of comparison. Allowable values are <, <=, <>, =, >=, >, and also starts with and contains (string fields only). The default value is = (equals).

SkipIfEmpty

Specifies how to handle the range condition when a variable contained within the ValueExpression is empty. If True (the default), the range condition is skipped; that is, it will not restrict the resulting recordset. The default setting (True) is useful for ad-hoc query forms where the user is not required to specify values for all fields.

ValueExpression

Specifies the operand to be used for comparison. The resulting range condition is field op value, where field is the data field that owns this range condition, op is the selected comparison operation, and value is the result of this expression.

ConditionExpression

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

 

 


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

Product Support Forum  |  Documentation Feedback