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:
Dataset1.Filter := 'State = ' + QuotedStr('CA');
Dataset1->Filter = "State = 'CA'";
You can also supply a value for Filter based on text supplied by the user. For example, the following statement assigns the text in from edit box to Filter:
Dataset1.Filter := Edit1.Text;
Dataset1->Filter = Edit1->Text;
You can, of course, create a string based on both hard-coded text and user-supplied data:
Dataset1.Filter := 'State = ' + QuotedStr(Edit1.Text);
Dataset1->Filter = AnsiString("State = '") + Edit1->Text + "'";
Blank field values do not appear unless they are explicitly included in the filter:
Dataset1.Filter := 'State <> ''CA'' or State = BLANK';
Dataset1->Filter = "State <> 'CA' or State = BLANK";
Comparison and logical operators that can appear in a filter
Operator |
Meaning |
< |
Less than |
> |
Greater than |
>= |
Greater than or equal to |
<= |
Less than or equal to |
= |
Equal to |
<> |
Not equal to |
AND |
Tests two statements are both True |
NOT |
Tests that the following statement is not True |
OR |
Tests that at least one of two statements is True |
+ |
Adds numbers, concatenates strings, adds numbers to date/time values (only available for some drivers) |
- |
Subtracts numbers, subtracts dates, or subtracts a number from a date (only available for some drivers) |
* |
Multiplies two numbers (only available for some drivers) |
/ |
Divides two numbers (only available for some drivers) |
* |
wildcard for partial comparisons (FilterOptions must include foPartialCompare) |
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:
(Custno > 1400) AND (Custno < 1500);
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
|
What do you think about this topic? Send feedback!
|