Incremental search routine using Tsbrowse needed

Incremental search routine using Tsbrowse needed

Postby RAMESHBABU » Mon Oct 08, 2007 5:43 am

Hi friends

Can anybody share the Incremental Search routine using TsBrowse.

I have a get and as i keep entering values in the get, the same values
should be searched in the attached Tsbrowser.

Thanks

- Ramesh Babu P
User avatar
RAMESHBABU
 
Posts: 624
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Postby Antonio Linares » Mon Oct 08, 2007 7:15 am

Ramesh,

Here you have it. In this example a GET is not needed, but you may easily add it:
Code: Select all  Expand view
#include "FiveWin.ch"

REQUEST DBFCDX

//----------------------------------------------------------------------------//

function Main()

   local oWnd, oBrw, hBmp := ReadBitmap( CurDir() + "\go.bmp" )
   local oSay, cSearch := ""

   USE ( CurDir() + "\Customer" ) VIA "DBFCDX"
   if ! File( CurDir() + "\LAST.CDX" )
      INDEX ON Customer->Last TO ( CurDir() + "\LAST" )
   endif   
   Customer->( OrdSetFocus( "LAST" ) )
   Customer->( DbGoTop() )

   DEFINE WINDOW oWnd TITLE "IncSearch"
   
   @ 1, 1 LISTBOX oBrw ;
      FIELDS hBmp, Customer->Last, Customer->First ;
      HEADERS "", "Last", "First" ;
      SIZE 220, 167
   
   oBrw:bKeyChar = { | nKey, nFlags | Search( nKey, @cSearch ), oBrw:Refresh(),;
                                      oSay:Refresh() }
   
   @ 14,  2 SAY "Searching:" SIZE 60, 30
   @ 14, 12 SAY oSay PROMPT cSearch SIZE 80, 30
   
   ACTIVATE WINDOW oWnd ;
      ON CLICK MsgInfo( "Click!" )
   
return nil

//----------------------------------------------------------------------------//

function Search( nKey, cSearch )

   if nKey = 8
      cSearch = SubStr( cSearch, 1, Len( cSearch ) - 1 )
   else
      cSearch += Upper( Chr( nKey ) )
   endif
   
   Customer->( DbSeek( cSearch, .t. ) )

return nil

//----------------------------------------------------------------------------//
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42079
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Richard Chidiak » Mon Oct 08, 2007 10:59 am

Antonio

Can you help showing a sample with get and incremental search on a listbox ?

Thanks for your time,

Richard
http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013
User avatar
Richard Chidiak
 
Posts: 946
Joined: Thu Oct 06, 2005 7:05 pm
Location: France

Postby Antonio Linares » Mon Oct 08, 2007 12:04 pm

Richard,

Do you mean a browse ?

Same example but typing on a GET ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42079
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby James Bott » Mon Oct 08, 2007 12:36 pm

Here is a more sophisticated example. It will only accept keystrokes that find a new match in the browse, otherwise it rejects the keystroke. There is a sound for each valid keystroke and no sound for invalid keystrokes.

James

-----------------------
Notes: If you return a logical from the bChange codeblock the GET will either accept or reject the last character. Very useful. Also note the use of a local copy of an instance var for use in a codeblock. I can't figure out why the GET won't accept commas.


Code: Select all  Expand view
  // Incremental search of the contact list using a GET.
  // Here we process keys dynamically in the contact lookup Get.
  // We have to compensate for the use of the numeric keypad.
   cClient:= space(20)

   // Create a local copy so we can use it in the codeblock below
   // Not needed if you are not using an instance var.
   oLbx2:= ::oLbx2

   // Bug: The GET below doesn't accept commas for some reason.

   @ 25,5 get oGet var cClient of oBar2 ;
     pixel;
     size 120,20 ;
     on change ( nOldRec:=self:cargo:recno(),;
      oGet:nLastKey:=if( getKeyToggle(VK_NUMLOCK), oGet:nLastKey - 48, oGet:nLastKey ),;
      cText:=trim(self:cText)+if(self:nLastKey>=32,chr(self:nLastKey),""),;
      if(self:cargo:seek(upper(cText)), (click(),lAccept:=.t.), (self:cargo:goto(nOldRec),lAccept:=.f. ) ),;
      oLbx2:refresh(),lAccept )

   oGet:cargo:= ::oContact2

function click()
   sndPlaySound("click.wav",2)
return nil
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby Richard Chidiak » Mon Oct 08, 2007 2:25 pm

Antonio ,

Yes

This will be very handy, it has been done with btnget but rather complex to use. I prefer a more flexible solution

Thanks

Richard
http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013
User avatar
Richard Chidiak
 
Posts: 946
Joined: Thu Oct 06, 2005 7:05 pm
Location: France

Postby RAMESHBABU » Mon Oct 08, 2007 2:29 pm

Mr.Antonio, Mr.James

Thank you very much for your samples.

Mr.Antonio's example is very interesting and very simple!.

I could't immediately understood the sample of
Mr.James.

Anyway, I could implement my requirement
very well using Tsbrowse for incremental search in
an array of database fields.

Regards

Ramesh Babu P
Last edited by RAMESHBABU on Mon Oct 08, 2007 3:31 pm, edited 1 time in total.
User avatar
RAMESHBABU
 
Posts: 624
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Postby RAMESHBABU » Mon Oct 08, 2007 3:30 pm

Mr.Richard

I hope this is what you wanted in respect of incremental search with
a get object.

Regards

- Ramesh Babu P

Code: Select all  Expand view
#include "FiveWin.ch"

REQUEST DBFCDX

* Incremental Search with a get object Example

//-----------------------------------------------------------------------//

FUNCTION Main()

LOCAL oWnd, oBrw
LOCAL cSearch, oSearch

USE Customer VIA "DBFCDX"
INDEX ON Customer->Last TO LAST 
OrdSetFocus( "LAST" )
DbGoTop()

cSearch := SPACE(LEN(Customer->Last))

DEFINE WINDOW oWnd TITLE "IncSearch"                ;
       FROM 1,100 TO 212,408 PIXEL NOMAXIMIZE
   
@  4,3 GET oSearch VAR cSearch OF oWnd              ;
       PIXEL size 145,17                            ;
       PICTURE "@!"                                 

@ 30,1 LISTBOX oBrw                                 ;
       FIELDS Customer->Last, Customer->First       ;
       HEADERS "Last","First"                       ;
       SIZE 300, 155 PIXEL

* This is the main trick.
oSearch:bPostKey = { || Search(oSearch:oGet:buffer),;
                        oBrw:Refresh() }
   
ACTIVATE WINDOW oWnd ON INIT WndCenter(oWnd:hWnd)
   
RETURN nil

//-----------------------------------------------------------------------//

FUNCTION Search(cSearch )

DbSeek( cSearch, .t. )

RETURN nil

**********
User avatar
RAMESHBABU
 
Posts: 624
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 52 guests