FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour AUTO SEARCH COMBOBOX - METHOD KeyChar
Posts: 1286
Joined: Mon Feb 25, 2008 02:54 PM
AUTO SEARCH COMBOBOX - METHOD KeyChar
Posted: Thu Aug 28, 2008 02:39 PM

Sr. Antonio,

Fiz a seguinte alteração na classe TCOMBOBOX para que a pesquisa aceita-se a tecla 32 (barra de espaço):

Gostaria de saber se está alteração acarretará algum problema?

METHOD KeyChar( nKey, nFlags ) CLASS TComboBox

local nNewAT := 0, nOldAT := ::nAT, uItem

do case
/*
Para funcionar a barra de espaço

  case nKey = 32   // VK_DELETE (DO NOT WORK!)
       ::cSearchKey = ""
       nNewAt = 1
       uItem  = ::aItems[ nNewAt ]

*/
case nKey = VK_BACK
::cSearchKey = Left( ::cSearchKey, Len( ::cSearchKey ) - 1 )

  case nKey = 190
       nKey = 0
       ::cSearchKey += "."

  otherwise
       ::cSearchKey += Upper( Chr( nKey ) )

endcase

if Empty( uItem )
if nNewAt == 0
nNewAt = AScan( ::aItems, {|x| Upper(x) = ::cSearchKey } )
if nNewAt > 0 .and. Len( ::aItems ) <= nNewAt
uItem = ::aItems[ nNewAt ]
endif
uItem = ::aItems[ If( nNewAt > 0, nNewAt, Max( ::nAT, 1 ) ) ]
else
uItem = ::aItems[ Max( nNewAt, 1) ]
endif
endif
::Set( If( ValType( Eval( ::bSetGet ) ) == "N", AScan( ::aItems, uItem ), uItem ) )

if ::bChange != nil .and. ( nNewAT != nOldAt .and. nNewAt != 0 )
Eval( ::bChange, Self, ::VarGet() )
endif

if nKey == VK_RETURN
return ::oWnd:GoNextCtrl( ::hWnd )
endif

return 0 // Must be 0 - We don't want API default behavior.

ubiratanmga@gmail.com

FWH24.04
BCC7.3
HARBOUR3.2
xMate
Pelles´C
TDolphin
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
AUTO SEARCH COMBOBOX - METHOD KeyChar
Posted: Sun Aug 31, 2008 06:20 PM
Si no vas a usar la búsqueda incremental, lo mejor es deshabilitarla completamente.

En FWH 8.08 hemos añadido una nueva DATA lIncSearch AS LOGICAL que es .F. por defecto, y el método KeyChar queda así:
METHOD KeyChar( nKey, nFlags ) CLASS TComboBox 

   local nNewAT := 0, nOldAT := ::nAT, uItem 

   if Len( ::aItems ) == 0 
      return 0 
   endif

   if ::lIncSearch
      do case 
         case nKey = 32   // VK_DELETE (DO NOT WORK!) 
              ::cSearchKey = "" 
              nNewAt = 1 
              uItem  = ::aItems[ nNewAt ] 
            
         case nKey = VK_BACK 
              ::cSearchKey = Left( ::cSearchKey, Len( ::cSearchKey ) - 1 ) 
            
         case nKey = 190 
              nKey = 0 
              ::cSearchKey += "." 
            
         otherwise 
              ::cSearchKey += Upper( Chr( nKey ) ) 
      endcase 
    
      if Empty( uItem ) 
         if nNewAt == 0 
            nNewAt = AScan( ::aItems, {|x| Upper(x) = ::cSearchKey } ) 
            if nNewAt > 0 .and. Len( ::aItems ) <= nNewAt 
               uItem = ::aItems[ nNewAt ] 
            endif 
            uItem = ::aItems[ If( nNewAt > 0, nNewAt, Max( ::nAT, 1 ) ) ] 
         else 
            uItem = ::aItems[ Max( nNewAt, 1) ] 
         endif  
      endif 
      ::Set( If( ValType( Eval( ::bSetGet ) ) == "N", AScan( ::aItems, uItem ), uItem ) ) 
   endif   

   if ::bChange != nil .and. ( nNewAT != nOldAt .and. nNewAt != 0 ) 
      Eval( ::bChange, Self, ::VarGet() ) 
   endif 

   if nKey == VK_RETURN 
      return ::oWnd:GoNextCtrl( ::hWnd ) 
   endif 

return If( ::lIncSearch, 0, nil )
regards, saludos

Antonio Linares
www.fivetechsoft.com

Continue the discussion