Solved

SEARCH FILTER! EASY POINTS!

Posted on 1998-01-21
9
149 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
 

Author Comment

by:aj85
ID: 1357247
Igor,

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

Tony
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now