Software snipets for the Delphi & Pascal Community
Sep 05, 2010 - 05:41 AM
alt1
Borland :: Mailing Lists
alt1
Search  
alt1
alt1 alt1 alt1
alt1
Main Menu
alt1
· Home
· Your Account

Other Options

· AvantGo
· Downloads
· FAQ
· Members List
· Messages
· News
· Recommend Us
· Reviews
· Search
· Sections
· Stats
· Submit News
· Topics
· Top List
· Web Links

alt1
Who's online
alt1
There are currently, 7 guest(s) and 0 member(s) online.

You are an anonymous user. You can register for free by clicking here


alt1
alt1
Allow Incremental Searching in your TDataSets
Posted by: Gayle
alt1
Topic General Database Handling
If you implement your search box (against a TDataSet) with a regular Locate() or FindKey() call requires that the user has typed in the exact search expression.

It is much more handy to jump to the first match based on a partial search.
E.g. if your user searches for the month 'August' in the list of 12 months' names, the user would type in 'A' and the cursor would jump to 'April'. Then the user would type the second letter.. 'u' and 'August' would be selected.

This is called 'Incremental Searching'.

The following piece of code shows how to do it - put it as the onChange event handler of your form's edit box.


procedure TForm1.Edit1Change(Sender: TObject);
begin
// empty? then do nothing!
if Edit1.Text='' then
exit;

//goto nearest match
with Table1
do
begin
SetKey;
FieldByName('Month').AsString := Edit1.Text;
GotoNearest;
end;
end;


alt1
alt1
 
alt1
Login
alt1
Username

Password

Don't have an account yet? You can create one. As a registered user you have some advantages like a theme manager, comments configuration and posting comments with your name.

alt1
Related links
alt1
· More about General Database Handling
· News by admin


Most read story in General Database Handling:
Fix Conflict between TDatabase & TObject


Printer friendly page  Send this story to a friend

alt1
Report Bugs :: Tasks :: Developers 
alt1




alt1