Solved

SEARCH FILTER! EASY POINTS!

Posted on 1998-01-21
9
152 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
Help on project with Soap 10 57
Delphi Form ownership 4 107
Delphi inherited method 6 75
How to remove Recent Projects from Embarcadero C++ builder XE10. Berlin 2 66
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used.

790 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