?
Solved

SEARCH FILTER! EASY POINTS!

Posted on 1998-01-21
9
Medium Priority
?
156 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 100 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month14 days, 14 hours left to enroll

770 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