Incremental lookup in a browse.

Incremental lookup in a browse.

Postby HunterEC » Wed Apr 08, 2009 8:25 am

How can I implement an incremental lookup as soon as I open a database browse ?
HunterEC
 
Posts: 723
Joined: Tue Sep 04, 2007 8:45 am

Re: Incremental lookup in a browse.

Postby Antonio Linares » Sun Apr 12, 2009 11:18 pm

regards, saludos

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

Re: Incremental lookup in a browse.

Postby HunterEC » Thu Apr 16, 2009 8:30 am

Antonio:

Thank you for your help. I tried the program in the thread that you specified but I noticed that it only looks on one character type by the user. For example, if I want to look up the name Alfred, after typing the letter A, I cannot continue to type the rest of the name, thus not doing an incremental search.
HunterEC
 
Posts: 723
Joined: Tue Sep 04, 2007 8:45 am

Re: Incremental lookup in a browse.

Postby Antonio Linares » Thu Apr 16, 2009 9:38 am

Gustavo,

This is an easy example for an incremental search using TWBrowse.
We are going to provide you a similar example with TXBrowse

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: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Incremental lookup in a browse.

Postby Antonio Linares » Thu Apr 16, 2009 2:21 pm

Gustavo,

Implementing Incremental Seek in xBrowse is extremely simple. XBrowse
auomates most of the work.

All that is required is only one single stament:
Code: Select all  Expand view

  @ <nRow>,<nCol> SAY oBrw:oSeek PROMPT oBrw:cSeek SIZE
<nWidth>,<nHeight> PIXEL OF oDlg
 

We emphasize this point. All other work, XBrowse automatically handles.
Here is a working example:

Note: In the case of Customer table, the seek expression is case sensitive.
Code: Select all  Expand view

//--------------------------------------------
#include "FiveWin.ch"
#include "xbrowse.ch"

REQUEST DBFCDX

function Main()

  local oDlg, oBrw, oFont

  CheckIndexes()  // required only for this sample

  USE CUSTOMER SHARED VIA "DBFCDX"
  Customer->( OrdSetFocus( "FIRST" ) )
  Customer->( DbGoTop() )

  DEFINE FONT oFont NAME 'TAHOMA' SIZE 0,-14
  DEFINE DIALOG oDlg SIZE 600,600 PIXEL ;
     TITLE "XBrowse Incremental Seek" ;
     FONT oFont

  @ 10,10 XBROWSE oBrw ;
     SIZE 280,230 PIXEL ;
     OF oDlg ;
     ALIAS "CUSTOMER" ;
     AUTOCOLS AUTOSORT LINES CELL

  @ 250,10 SAY oBrw:oSeek PROMPT oBrw:cSeek SIZE 280,10 PIXEL OF oDlg ;
     COLOR CLR_BLACK, CLR_YELLOW

  oBrw:CreateFromCode()

  ACTIVATE DIALOG oDlg CENTERED
  RELEASE FONT oFont

return nil
//-----------------------------------------------------------------------------//

*
* following code is only for the sample
*
*
static function CheckIndexes()

  local n

  if File( "customer.cdx" )
     FErase( "customer.cdx" )
  endif

  USE CUSTOMER EXCLUSIVE VIA "DBFCDX"
  for n := 1 to FCount()
     CreateTag( FieldName( n ) )
  next
  USE

return nil

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

static function CreateTag( ctag )

  INDEX ON &ctag TAG &ctag

return nil

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

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

Re: Incremental lookup in a browse.

Postby HunterEC » Mon Apr 20, 2009 9:50 am

Antonio:
Kudos ! Great example, superb, magnífico ! Your xbrowse class is very welcome !
HunterEC
 
Posts: 723
Joined: Tue Sep 04, 2007 8:45 am

Re: Incremental lookup in a browse.

Postby HunterEC » Tue Apr 21, 2009 5:47 am

Antonio:

Why after typing an argument for the incremental search, if the user navigate the browse with the up/down arrows, the cSeek / oSeek variables loses their data ? Can this be avoided ? Thank you
HunterEC
 
Posts: 723
Joined: Tue Sep 04, 2007 8:45 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 103 guests