Page 1 of 1
increment search in DBF BROWSE
Posted: Wed Nov 25, 2020 6:17 am
by AUGE_OHR
i know the HMG Sample but it is based on Array GRID
i do have Problem with it when try with DBF so i wrote a new Version.
it include these Listview Function
Procedure ItemMark()
Procedure UnMarkAll()
Function ListView_GETSELECTIONMARK()
Function ListView_GETNEXTITEM()
Function ListView_GETSELECTEDCOUNT()
Sample work with "Outlook" DBF Structure here
https://www.hmgforum.com/viewtopic.php?f=5&t=6686

- DBFinc.jpg (62.24 KiB) Viewed 2000 times
Re: increment search in DBF BROWSE
Posted: Wed Nov 25, 2020 8:22 am
by AUGE_OHR
hi,
i miss 1 line in last Version ... sorry
Code: Select all
PROCEDURE DoSearchSubject()
LOCAL cSeek := TRIM( SearchForm.SearchText.Value )
LOCAL nRecno := RECNO()
LOCAL hGrid
SEEK( UPPER( cSeek ) )
IF FOUND()
nRecno := RECNO()
Domethod( "SearchForm", "SearchGrid", "REFRESH" )
hGrid := GetControlHandle( "SearchGrid", "SearchForm" )
UnMarkAll( hGrid, .T. )
// this line need before mark
Setproperty( "SearchForm", "SearchGrid", "VALUE", nRecno )
ItemMark( hGrid, nRecno )
ELSE
GOTO( nRecno )
ENDIF
RETURN
Re: increment search in DBF BROWSE
Posted: Wed Nov 25, 2020 10:56 am
by mustafa
Hi jimmy
Look at this code?
Search for any Letter
Code: Select all
STATIC PROCEDURE DoSearchSubject()
PRIVATE Filtro
USE OUTLOOK INDEX OUTLOOK
IF LEN( SearchForm.SearchText.Value) != 0
Filtro := LOWER(SearchForm.SearchText.Value)
SET FILTER TO AT(Filtro,OUTLOOK->SUBJECT) <>0
SET FILTER TO FILTRO $ OUTLOOK->SUBJECT
SET SOFTSEEK ON
GO TOP
SearchForm.SearchGrid.value := OUTLOOK->(RecNo())
SearchForm.SearchGrid.Refresh
ELSE
SET FILTER TO
SearchForm.SearchGrid.value := OUTLOOK->(RecNo())
SearchForm.SearchGrid.Refresh
ENDIF
SET SOFTSEEK OFF
RETURN
Regards
Mustafa
Re: increment search in DBF BROWSE
Posted: Wed Nov 25, 2020 9:01 pm
by AUGE_OHR
hi,
mustafa wrote: ↑Wed Nov 25, 2020 10:56 am
Look at this code?
Search for any Letter
it is not the Way to "search" ... it is to display in BROWSE "while type" into Keyboard.
SET FILTER can be very slow with big Database and not need for "Quick Search" to navigate in BROWSE.
i guess your Code is when have "full String" to search while i want "increment search" after every Keystoke.
Re: increment search in DBF BROWSE
Posted: Thu Nov 26, 2020 8:18 am
by SALINETAS24
Hola Jimmy.
Te paso la función que yo utilizo, de una manera algo distinta a lo que tu quieres pero puede ser que te muestre el camino.
En mi caso yo cargo un grid con los campos que cumple la condición y utilizo (OrdWildSeek( "*" + cCod + "*",.T. ) ), que con los asteriscos "*" me permite buscar en cualquier posición del campo.
Recibe un saludo.
Code: Select all
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
// --> Busca_Aprox
// ----------------------------------------------------------------------
// --> Busca registros por aproximación.
// --> Solo cuando son indices Alfabeticos
// ----------------------------------------------------------------------
// --> LLAMADA --> Busca_Aprox(cCod,cArea,nOrden)
// ----------------------------------------------------------------------
// --> DEVUELVE--> Numero del Registro seleccionado - 0 no hay selección.
// ----------------------------------------------------------------------
// --> Parametros
// cCod --> Cadena de Caracteres a buscar
// cArea --> Alias del fichero
// nOrden --> Numero de Indice que se activará para realizar la busqueda.
// ----------------------------------------------------------------------
FUNC Busca_Aprox(cCod,cArea,nOrden)
LOCAL cIndiceActivo , nArea
LOCAL aItem := {}
LOCAL nRec:=0
* msgbox(cCod+" -- "+cArea+" -- "+ str(nOrden) )
nArea := (cArea)->( INDEXORD() )
(cArea)-> (DbSetOrder(nOrden))
cIndiceActivo := (cArea)->( INDEXORD() )
IF TYPE((cArea)->(INDEXKEY(cIndiceActivo)))="C"
(cArea)->(DbGoTop())
// --> No funciona con claves numericas
* DO WHILE IF(TYPE((cArea)->(INDEXKEY(cIndiceActivo)))="N",OrdWildSeek(cCod,.T. ) , OrdWildSeek( "*" + cCod + "*",.T. ) )
DO WHILE (cArea)->(OrdWildSeek( "*" + cCod + "*",.T. ) )
AAdd( aItem, {(cArea)->(FIELDGET(1)),(cArea)->(FIELDGET(2)),(cArea)->(Recno())} )
ENDDO
IF LEN(aItem)>0
DEFINE WINDOW Form_1 AT 0,0 WIDTH 350 HEIGHT 550 ;
TITLE 'Busqueda de Registros' ;
MODAL ;
BACKCOLOR { 209,220,231 } ;
FONT "Arial" SIZE 10 ;
NOSIZE
@ 15,5 GRID Grid_1 ;
WIDTH 335 ;
HEIGHT 500 ;
HEADERS {(cArea)->(FIELDNAME(1)),(cArea)->(FIELDNAME(2)),"Np"} ;
WIDTHS {100,270,3};
ITEMS aItem ;
VALUE 1 ;
ON DBLCLICK (nRec:=VAL(ValorCelda("Form_1", "Grid_1",3)),ThisWindow.Release() )
END WINDOW
CENTER WINDOW Form_1
ACTIVATE WINDOW Form_1
ELSE
lMsgExclamation("No hay Registros","ATENCION")
ENDIF
ELSE
//--> Es númerica, la busco
IF (cArea)->(DbSeek(VAL(cCod)))
nRec:= (cArea)->(Recno())
ENDIF
ENDIF
(cArea)->(DbSetOrder(nArea))
RETURN nRec
Re: increment search in DBF BROWSE
Posted: Thu Nov 26, 2020 12:14 pm
by AUGE_OHR
hi,
thx for Code but my Problem is NOT to Seek() / OrdwildSeek().
when use
Code: Select all
ON CHANGE DoSearchSubject()
PROCEDURE DoSearchSubject()
LOCAL cSeek := TRIM( SearchForm.SearchText.Value )
SEEK( UPPER( cSeek ) )
IF FOUND()
nRecno := RECNO()
Domethod( "SearchForm", "SearchGrid", "REFRESH" )
it does move Pointer ...
but it is not "hight-light" in BROWSE / GRID while Focus is on TEXTBOX where i type
so i add some Listview API Function
Code: Select all
// now geht Handle of BROWSE
hGrid := GetControlHandle( "SearchGrid", "SearchForm" )
// unmark 1st
UnMarkAll( hGrid, .T. )
// now set Value to GRID
Setproperty( "SearchForm", "SearchGrid", "VALUE", nRecno )
// mark it and make it visible in BROWSE / GRID Area
ItemMark( hGrid, nRecno )
ELSE
GOTO( nRecno )
ENDIF

- Increment_Search.gif (229.25 KiB) Viewed 1843 times
IMHO those Listview Function are missing so i posted them in Demo.
hm ... it does not work with Demo Sample ... but it is same Code ...

Re: increment search in DBF BROWSE
Posted: Fri Nov 27, 2020 7:58 am
by SALINETAS24
Hola Jimi, entiendo que quieres pintar una fila determinada de tu BROWSE. La que esta activa en la búsqueda.
Para el control GRID existe la opción ColumnDYNAMICBACKCOLOR, que te permitiría marcar la fila seleccionada, pero NO existe para BROWSE. Con esta función te evitas el refresh continuo.
Mirate esto, te puede resultar interesante y diviertete!!
viewtopic.php?f=5&t=5742&p=55838&hilit= ... LOR#p55838
Un saludo virtual con una cervecita bien fresquita!!
Re: increment search in DBF BROWSE
Posted: Fri Nov 27, 2020 5:50 pm
by franco
Jimmy, try this it can be elaborated on.
Code: Select all
#include <hmg.ch>
PROC Main()
tbls()
use inv new shared
index on num1 to num1
DEFINE WINDOW frmQSMain ;
AT 0,0 ;
WIDTH GetDesktopWidth() * 0.75 ;
HEIGHT GetDesktopHeight() * 0.75 ;
TITLE "Quick Search Implementation on HMG Reference Guide" ;
MAIN
ON KEY ESCAPE ACTION frmQSMain.Release
ON KEY ESCAPE ACTION ''
DEFINE COMBOBOX button_1 // FOR BUTTON TO CLICK
ROW 10
COL 211
WIDTH 20
HEIGHT 20 // 20
ON GOTFOCUS { || frmQSMain.textSEARCH.VISIBLE := .T. , frmQSMain.brwItems.VISIBLE := .T. , frmQSMain.textSEARCH.setfocus }
END COMBOBOX
DEFINE BROWSE brwItems
ROW 33 //33
COL 211
WIDTH 330
HEIGHT 290 //290
BACKCOLOR {220,220,228}
HEADERS { "Item","Description"}
WIDTHS { 100,200 }
WORKAREA inv
FIELDS { 'inv->num1', 'inv->desc' }
ONDBLCLICK { || frmQSMain.text_1.refresh , frmQSMain.textSEARCH.VISIBLE := .F. , frmQSMain.brwItems.VISIBLE := .F. }
ONLOSTFOCUS { || frmQSMain.text_1.refresh , frmQSMain.textSEARCH.VALUE := '' , ;
frmQSMain.brwItems.VISIBLE := .F. , frmQSMain.textSEARCH.VISIBLE := .F. , ;
frmQSMain.textSEARCH.VALUE := ' ' }
ONCHANGE { || dbgoto(this.value) }
NOLINES .T.
END BROWSE // brwItems
DEFINE TEXTBOX textSearch
ROW 10
COL 232
WIDTH 200 // 200 can make 0 so you cannot see
HEIGHT 24
ONCHANGE { || DBSEEK( UPPER( this.Value ), .T. ), frmQSMain.brwItems.value := inv->(RECNO() ) }
ONENTER { || frmQSMain.brwItems.SETFOCUS }
ONLOSTFOCUS { || frmQSMain.brwItems.SETFOCUS}
END TEXTBOX // tbxSearch
DEFINE TEXTBOX text_1
ROW 10
COL 10
WIDTH 200
HEIGHT 24
FIELD INV->NUM1
END TEXTBOX
END WINDOW // frmQSMain
frmQSMain.text_1.SETFOCUS
frmQSMain.textSEARCH.VISIBLE := .F.
frmQSMain.brwItems.VISIBLE := .F.
frmQSMain.Center
frmQSMain.Activate
return
// HMG_HELP Main()
*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.
FUNCTION TBLS
LOCAL CF := {}
if ! file('inv.dbf')
CF := {}
aADD(CF,{'NUM1' ,'C' , 15,0})
aADD(CF,{'DESC' ,'C' , 15,0})
DBCREATE( 'INV.DBF',CF )
USE
use inv new
index on num1 to num1
set index to num1
do while recno() < 1000000
append blank
replace num1 with alltrim(str(100+recno()))
replace desc with 'DESC' +alltrim(str(100+recno()))
loop
enddo
close inv
endif
return
The first time in it takes a bit to create file, but index is quick.