Solved

SEARCH FILTER! EASY POINTS!

Posted on 1998-01-21
9
151 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
  • 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

808 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