Solved

SEARCH FILTER! EASY POINTS!

Posted on 1998-01-21
9
154 Views
Last Modified: 2010-04-04
I need to create a filter to search through a small DB by state or city. How can I do this?
0
Comment
Question by:aj85
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 5

Accepted Solution

by:
ronit051397 earned 50 total points
ID: 1357244
This is from Delphi Help file:
The Filter property is a string that lets you specify which records you want to see in the data set. Filters are similar to, though less powerful than, queries, with the benefit that filters work on the data set itself, meaning that the result is always "live" (unlike queries which sometimes produce result sets that can't be modified). You can turn a filter on and off by changing the Filtered property.
The syntax for the filter string is very similar to that used in the WHERE clause of an SQL statement. You can compare fields to other fields and to literal values, using the comparison operators in the following table:

Operator      Meaning

<      Less than
>      Greater than
>=      Greater than or equal to
<=      Less than or equal to
=      Equal to
<>      Not equal

For example,

PatientAge >= 18
      Temperature < 212
      SalePrice < BulkPrice

You can use the AND, NOT, and OR operators to combine comparisons:

(PatientAge >= 18) AND (Balance > 0)
      (Temperature < 212) AND (NOT Windy)
      (SalePrice < BulkPrice) OR (Terms > 30)

Enclose field names with spaces in square brackets:

[Patient Age] > 18

Use Filter to specify a dataset filter. When filtering is applied to a dataset, only those records that meet a filter’s conditions are available to an application. Filter contains the string that describes the filter condition. For example, the following filter condition displays only those records where the State field is 'CA' or 'MA':

State = 'CA' or State = 'MA'

To filter strings bases on partial comparisons, use an asterisk as a wildcard. For example:

State = 'M*'

Note

Applications can set Filter at runtime to change the filtering condition for a dataset at (for example, in response to user input).

As for your case:
if the name of the field is city and you want to filter records that refer to Paris, you write:
Table1.Filtered:=True;
Table1.Filter:='city=Paris';
0
 
LVL 5

Expert Comment

by:inter
ID: 1357245
Does your table contain indexes assigned to state or city fields? If so, we can use SetRange and CancelRange methods of TTable to do the task you required.

Waiting for reply,
Igor
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1357246
Well what if I want it to filter through a listbox that contains a lists of cities and state. How can I have it filter when the enduser enters the first letter of the state such as G for GA or T for TX and so on.  Is there a way to do that?

Thanks
Tony
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:aj85
ID: 1357247
Igor,

Yes my app does contain indexes for state & city, what is you solution?

Tony
0
 

Author Comment

by:aj85
ID: 1357248
Table1.Filter:='City='G*'';
0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1357249
What about in a Grid, what should I do then.  Also what if I want to filter with a wild card for any state or city?
0
 

Author Comment

by:aj85
ID: 1357250
Dear aj85,
My solution is to define a range using SetRangeXXX, EditRangeXXX, ApplyRange. For example

Let's restrict the record set so that the
 'BB'     <= State <= 'YY' and
 'Ben Lomond' <= City  <= 'Scotts Valley'

Assume we have
  IndexFieldNames = 'State;City';

The quick code for this is

with Table1 do
  begin
    SetRange(['BB','Ben Lomond'],        // Start value for keys
             ['YY','Scotts Valley'],);   // End value for keys
    ApplyRange;
  end;

This is the method I propese

Sincerely,
Igor
0
 
LVL 5

Expert Comment

by:inter
ID: 1357251
By using the filter, there is no need to index the fields.
0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1357252
Actually,
You are right Ronit. I think it is matter of preference.

Igor
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question