TDAMemDataTable filters (Delphi)

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

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

You can also supply a value for Filter based on text supplied by the user. For example, the following statement assigns the text from edit box to Filter:

table.Filter := Edit1.Text;

You can, of course, create a string based on both hard-coded text and user-supplied data:

table.Filter := 'State = ' + QuotedStr(Edit1.Text);

After you specify a value for Filter, to apply the filter to the TDAMemDataTable, set the Filtered property to True.

Filters can compare field values to literals and to constants using the following comparison and logical operators:

Boolean operators


Operator
Meaning
Usage
AND
Tests two statements that both have to be True
(fld1 > 10) AND (fld1 < 30)
NOT
Tests one statement that has to be not True
NOT (fld1 = 10)
OR
Tests that at least one of two statements is True
(fld1 = 11) OR (fld1 = 5)
XOR
Tests that at least one of two statements is not equal to the other one
(fld1 = 11) XOR (fld2 = 5)

Comparing operations


Operator
Meaning
Usage
<
Less than
fld1 < 10
>
Greater than
fld1 > 10
>=
Greater than or equal to
fld1 >= 10
<=
Less than or equal to
fld1 <= 10
=
Equal to
fld1 = 10
<>
Not equal to
fld1 <> 10
IS NULL
Test values for NULL
fld1 IS NULL
IS NOT NULL
Test values for NOT NULL
fld1 IS NOT NULL
IN
Tests values from specified list
fld1 IN (10,20)
LIKE
Finds a string fitting a certain description
fld1 LIKE 'a*'
fld1 LIKE '%a'

Logical operators and math symbols


Operator
Meaning
Usage
AND
bitwise and
(fld1 AND 10) = 10
NOT
bitwise negation
(NOT fld1) = 31
OR
bitwise or
(fld1 OR 10) = 40
XOR
bitwise xor
(fld1 XOR 10) = 0
+
addition
(fld1 + 10) = 30
-
subtraction
(fld1 - 10) = 10
*
multiplication
(fld1 * 10) < 30
/
real division
(fld1 / 10) > 10
%
modulus
(fld1 % 2) = 1
$
specifies that value in hex format
(fld1 + $10) < 100

Wildcards for partial comparisons for LIKE operator


Operator
Usage
*
fld1 LIKE 'abc*abc'
%
fld1 LIKE '%abc%'

By using combinations of these operators, you can create fairly sophisticated filters. For example, the following statement checks to make sure that two test conditions are met before accepting a record for display:

(fld1 > 1400) AND (fld1 < 1500)

When filtering is on, user edits to a record may mean that the record no longer meets a filter's test conditions. The next time the record is retrieved from the TDAMemDataTable, it may therefore "disappear." If that happens, the next record that passes the filter condition becomes the current record.