EasyTable: Single-File Embedded Database,
a BDE replacement for Delphi and C++Builder



Filtering records
Previous  Top  Next


Introduction

Setting filters on tables is accomplished through several methods of the TEasyTable component. The basic filter properties include the Filter, FilterOptions and Filtered properties. The OnFilterRecord event is used to implement a callback filter event that can be used to filter records using Delphi code. All filter operations keep current index order.


Setting the Filter property

To create a filter using the
Filter property, set the value of the property to a string that contains the filter conditions. The string contains the filter's test condition. For example, the following statement creates a filter that tests a table's State field to see if it contains a value for the state of California:

table1.Filter := 'State = ' + QuotedStr('CA');

you can also supply a value for
Filter based on the text entered in a control. For example, the following statement assigns the text from an edit box to Filter:

table1.Filter := Edit1.Text;

you can also create a condition for boolean fields:

table1.Filter := 'Married = TRUE';

you can also create a string based both on hard-coded text and on data entered by a user in a control:

table1.Filter := 'State = ' + QuotedStr(Edit1.Text);
you can also compare field values to literals, and to constants using the following logical and comparison operators:

Operator
Meaning
<
Less than
>
Greater than
>=
Greater than or equal to
<=
Less than or equal to
=
Equal to
<>
Not equal to
AND
Tested statements are both True
NOT
Tested statement is not True
OR
At least one of two statements tested is True
[NOT] LIKE
Extended operator for string field value comparisons with wildcards %,
IS [NOT] NULL
Extended operator for determining whether a field value is NULL


Using combinations of the above listed operators you can create fairly sophisticated filters. For example, the following statement checks if the two test conditions meet when searching for a record:

(Custno > 1400) AND (Custno < 1500);


Setting filter options

The FilterOptions property enables you to specify whether or not a filter that compares string-based fields accepts records based on partial comparisons and whether or not string comparisons are case-sensitive. FilterOptions is a set property that can be an empty set (the default), or that can contain either or both of the following values:

Value
Meaning
foCaseInsensitive
Ignore case when comparing strings.
foPartialCompare
Disable partial string matching (i.e., do not match strings ending with an asterisk (*)).


For example, the following statements set up a filter that ignores case when comparing values in the State field:

FilterOptions := [foCaseInsensitive];

Filter := '''State'' = ''CA''';


Activating filter

Set the Filtered property to True.
When filtering is enabled, only those records that meet the filter criteria are available to an application. Filtering is always a temporary condition. You can turn off filtering by setting the Filtered property to False.


© AidAim Software EasyTable: