Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 5 of 5 total
Thread How incremental search
Fri, Jun 2 2017 8:06 PMPermanent Link

Peter van Mierlo

EVENTSOFT

hi

I use a TEdit where the user can enter his search string.
Then he has to click on the search button which executes this code :

          with Country do begin
           Columns['Name'].SortDirection:=sdAscending;
           SortCaseInsensitive:=True;
           Sort;
           InitFind;
           Columns['Name'].AsString:=Edit_Search.Text;
           if Find(False,True) then
              Result:=True
           else
              Result:=False;
           end;

When the user enters the full name the record will be find.
Now i would only enter a couple of letters to search.

Lets say he want to search for records which contains the string 'Land'

How can that be done ?

Regards Peter
Fri, Jun 2 2017 10:26 PMPermanent Link

erickengelke

Peter van Mierlo wrote:
>I use a TEdit where the user can enter his search string.
>Then he has to click on the search button which executes this code :
>Lets say he want to search for records which contains the string 'Land'

Instead of testing equality, see if Pos( LowerCaw(a), LowerCase(b) ) > 0
Of course you would probably want to optimize that by calculating LowerCase() of the search term once and then reuse it.

Erick
http://www.erickengelke.com
Sat, Jun 3 2017 11:57 AMPermanent Link

Paul Waegemans

IMS bvba

Avatar

Use a query?

DatasetL_Clubslike:

SELECT KBVB,club_ID,Clubnaam,gc_mail,gc_tel2 FROM clubs
WHERE clubnaam LIKE{CLUBNAAM='%GENT%'} ORDER BY clubnaam

In programcode:

  L_ClubsLike.params.clear;
  L_ClubsLike.params.add('clubnaam='+quotedstr('%'+EdtClubZoeken.text+'%'));
  database.loadrows(L_ClubsLike);
 





Peter van Mierlo wrote:

hi

I use a TEdit where the user can enter his search string.
Then he has to click on the search button which executes this code :

          with Country do begin
           Columns['Name'].SortDirection:=sdAscending;
           SortCaseInsensitive:=True;
           Sort;
           InitFind;
           Columns['Name'].AsString:=Edit_Search.Text;
           if Find(False,True) then
              Result:=True
           else
              Result:=False;
           end;

When the user enters the full name the record will be find.
Now i would only enter a couple of letters to search.

Lets say he want to search for records which contains the string 'Land'

How can that be done ?

Regards Peter
Sun, Jun 4 2017 5:46 AMPermanent Link

erickengelke

Paul Waegemans wrote:
>Use a query?

In some cases I do incremental searches with a second TDataSet.

The first is a hidden DataSet1 which has all the data from the server,
then as you type, I scan it and filter out just the matching entries and copy them
to dataset2 which is referenced by the Grid.

This way I'm not bugging the server every second.

I set the TEdit's Tag field to 1 when the user presses a key, then in a 1 second timer
I do the above filtering if Edit's Tag is 1, and reset the Edit's Tag to 0 to indicate it need
not be searched again until another key press.  This works better than searching after every
keystroke for largish datasets (eg. 1000 entries).

Erick
http://www.erickengelke.com
Mon, Jun 5 2017 4:05 AMPermanent Link

Matthew Jones

erickengelke wrote:

> I set the TEdit's Tag field to 1 when the user presses a key, then in a 1 second timer

I too use a timer. Slightly more complex, but basically the same. The idea is to allow the user to type a few characters before they pause and then you do the lookup, so that the lookup is not fruitless.

The other thing is that I'm [often] doing a server call to get results, and so I use a flag to say a lookup is needed. The timer then checks to see if a lookup is already in progress, and does nothing if it is. When the existing call to the server returns, it checks the flag, and then initiates the next lookup. This means that the first change gets a search, but they can type several characters before the next one happens. Which saves a lookup for every character which would take more time.

--

Matthew Jones
Image