Hola Rathinagiri
Tratando de entender tu ejemplo con el "Create Event", hice lo siguiente: (pero no se si así es como deba funcionar)
* Siempre encuentra el primer registro "fer" pero existen 2
* Puse "ON INIT _ComboBoxAnywhereSearchInit( .f. )" para hacer la llamada a esta función // Pero da ERROR si pongo .T.
* Si pongo la propiedad SORT, me da ERROR
* En que momento se hace la llamada a la "funcion _ComboBoxAnywhereSearchClose( )"
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
Hello Rathinagiri
Trying to understand your example with the "Create Event", I did the following: (but not if this is how it should work)
* Always find the first record "fer" but there are two
* Put "ON INIT _ComboBoxAnywhereSearchInit (.f.)" To make the call to this function // But fails if I put .T.
* If you get the property SORT gives me ERROR
* At what point it is the call to "_ComboBoxAnywhereSearchClose() function"
- CreateEvent.jpg (156.78 KiB) Viewed 3461 times
Code: Select all
#include <hmg.ch>
PROCEDURE Main()
PUBLIC aRows [21], _cComboSearchString := '' // ERROR if it is not defined
aRows [1] := "Simpson Homer 555-5555"
aRows [2] := "Mulder Fox 324-6432"
aRows [3] := "Smart Max 432-5892"
aRows [4] := "Grillo Pepe 894-2332"
aRows [5] := "Kirk James 346-9873"
aRows [6] := "Barriga Carlos 394-9654"
aRows [7] := "Flanders Ned 435-3211"
aRows [8] := "Smith John 123-1234"
aRows [9] := "Pedemonti Flavio 000-0000"
aRows [10] := "Gomez Juan 583-4832"
aRows [11] := "Fernandez Raul 321-4332"
aRows [12] := "Borges Javier 326-9430"
aRows [13] := "Alvarez Alberto 543-7898"
aRows [14] := "Gonzalez Ambo 437-8473"
aRows [15] := "Batistuta Gol 485-2843"
aRows [16] := "Vinazzi Amigo 394-5983"
aRows [17] := "Pedemonti Flavio 534-7984"
aRows [18] := "Samarbide Armando 854-7873"
aRows [19] := "Pradon Alejandra ???-????"
aRows [20] := "Reyes Monica 432-5836"
aRows [21] := "Fernández two 000-0000"
DEFINE WINDOW txn AT 0,0 WIDTH 640 HEIGHT 480 TITLE 'CREATE EVENT TEST' MAIN ON INIT _ComboBoxAnywhereSearchInit( .f. ) // if .t. ERROR
@ 010, 010 COMBOBOX accounts ITEMS aRows VALUE 1 WIDTH 300 HEIGHT 200 FONT "Verdana" SIZE 12 TOOLTIP "cToolTipText" DROPPEDWIDTH 350 DISPLAYEDIT // SORT <=== ERROR
*[ ON GOTFOCUS <OnGotFocusProcedur> | <bBlock> ]
*[ ON CHANGE <OnChangeProcedure> | <bBlock> ]
*[ ON LOSTFOCUS <OnLostFocusProcedure> | <bBlock> ]
*[ ON ENTER <OnEnterProcedure> | <bBlock> ]
*[ ON DISPLAYCHANGE <OnDisplayChangeProcedure> | <bBlock> ]
*[ ON DROPDOWN <OnDropDownProcedure> | <bBlock> ]
*[ ON CLOSEUP <OnCloseUpProcedure> | <bBlock> ]
*[ IMAGE <acImageNames> ]
*[ ON CANCEL <OnCancelProcedure> | <bBlock> ]
*[ NOTRANSPARENT ]
END WINDOW
Create Event ProcName _ComboBoxAnywhereSearch( 'accounts', 'txn' ) HWND GetControlHandle ( 'accounts', 'txn' )
TXN.CENTER
TXN.ACTIVATE
RETURN nil
FUNCTION _ComboBoxAnywhereSearchInit( lShowLabel )
if .not. __mvexist( '_cComboSearchString' )
public _cComboSearchString := ''
endif
if lShowLabel
if .not. iscontroldefined( _combolabel, &( thiswindow.name ) )
define label _combolabel
parent &(thiswindow.name)
row this.row - 30
col this.col
width this.width
backcolor { 0, 0, 255 }
fontcolor { 255, 255, 255 }
fontname this.fontname // ERROR when lShowLabel = .t.
fontsize 14
fontbold .t.
autosize .t.
end label
endif
endif
RETURN nil
FUNCTION _ComboBoxAnywhereSearchClose( ) // when it called ?
if __mvexist( '_cComboSearchString' )
_cComboSearchString := ''
endif
if iscontroldefined( _combolabel, &(thiswindow.name))
domethod( thiswindow.name, '_combolabel', 'RELEASE' )
endif
RETURN nil
FUNCTION _ComboBoxAnywhereSearch( cComboName, cWindowName )
local lFound := .f.
local nEventMsg := EventMsg()
local ch
local nVKDown := HMG_GetLastVirtualKeyDown()
ch := HMG_GetLastCharacter()
HMG_CleanLastCharacter( .t. )
do case
case nVKDown == VK_BACK // backspace
HMG_CleanLastVirtualKeyDown()
_cComboSearchString := HB_ULEFT( _cComboSearchString, max( 0, ( HMG_Len( _cComboSearchString ) - 1 ) ) )
_ComboBoxAnywhereSearchUpdate( cWindowName )
case nVKDown == VK_UP .or. nVKDown == VK_DOWN
HMG_CleanLastVirtualKeyDown()
if hmg_len( _cComboSearchString ) == 0
return nil
else
nLineNo := getproperty( cWindowName, cComboName, 'VALUE' )
if nVKDown == VK_UP
lFound := .f.
for i := nLineNo - 1 to 1 step - 1
// first check in the starting chars...
if hmg_upper( _cComboSearchString ) == hb_uleft( hmg_upper( getproperty( cWindowName, cComboName, 'ITEM', i ) ), hmg_len( _cComboSearchString ) )
lFound := .t.
setproperty( cWindowName, cComboName, 'VALUE', i )
exit
endif
next i
if .not. lFound // anywhere searching...
for i := nLineNo - 1 to 1 step - 1
if HB_UAT( hmg_upper( _cComboSearchString ), hmg_upper( getproperty( cWindowName, cComboName, 'ITEM', i ) ) ) > 0
lFound := .t.
setproperty( cWindowName, cComboName, 'VALUE', i )
exit
endif
next i
endif
if .not. lFound
playbeep()
endif
else // down key search for next
lFound := .f.
for i := nLineNo + 1 to getproperty( cWindowName, cComboName, 'ITEMCOUNT' )
// first check in the starting chars...
if hmg_upper( _cComboSearchString ) == hb_uleft( hmg_upper( getproperty( cWindowName, cComboName, 'ITEM', i ) ), hmg_len( _cComboSearchString ) )
lFound := .t.
setproperty( cWindowName, cComboName, 'VALUE', i )
exit
endif
next i
if .not. lFound // anywhere searching...
for i := nLineNo + 1 to getproperty( cWindowName, cComboName, 'ITEMCOUNT' )
if HB_UAT( hmg_upper( _cComboSearchString ), hmg_upper( getproperty( cWindowName, cComboName, 'ITEM', i ) ) ) > 0
lFound := .t.
setproperty( cWindowName, cComboName, 'VALUE', i )
exit
endif
next i
endif
if .not. lFound
playbeep()
endif
endif
return 1
endif
case nVKDown == VK_ESCAPE
HMG_CleanLastVirtualKeyDown()
_cComboSearchString := ''
_ComboBoxAnywhereSearchUpdate( cWindowName )
return 1
case nVKDown == VK_RIGHT .or. nVKDown == VK_LEFT .or. nVKDown == VK_HOME .or. nVKDown == VK_END
HMG_CleanLastVirtualKeyDown()
_cComboSearchString := ''
_ComboBoxAnywhereSearchUpdate( cWindowName )
return nil
case EventIsMouseMessage ()
HMG_CleanLastVirtualKeyDown()
// _cComboSearchString := ''
_ComboBoxAnywhereSearchUpdate( cWindowName )
return nil
otherwise
IF nEventMsg <> WM_CHAR
Return Nil // enable processing the current message
ENDIF
_cComboSearchString := _cComboSearchString + ch
_ComboBoxAnywhereSearchUpdate( cWindowName )
endcase
lFound := .f.
for i := 1 to getproperty( cWindowName, cComboName, 'ITEMCOUNT' )
// first check in the starting chars...
if hmg_upper( _cComboSearchString ) == hb_uleft( hmg_upper( getproperty( cWindowName, cComboName, 'ITEM', i ) ), hmg_len( _cComboSearchString ) )
lFound := .t.
setproperty( cWindowName, cComboName, 'VALUE', i )
exit
endif
next i
if .not. lFound // anywhere searching...
for i := 1 to getproperty( cWindowName, cComboName, 'ITEMCOUNT' )
if HB_UAT( hmg_upper( _cComboSearchString ), hmg_upper( getproperty( cWindowName, cComboName, 'ITEM', i ) ) ) > 0
lFound := .t.
setproperty( cWindowName, cComboName, 'VALUE', i )
exit
endif
next i
endif
if .not. lFound
playbeep()
_cComboSearchString := HB_ULEFT( _cComboSearchString, max( 0, ( HMG_Len( _cComboSearchString ) - 1 ) ) )
_ComboBoxAnywhereSearchUpdate( cWindowName )
endif
RETURN 1
FUNCTION _ComboBoxAnywhereSearchUpdate( cWindowName )
if iscontroldefined( _combolabel, &cWindowName )
setproperty( cWindowName, '_combolabel', 'VALUE', _cComboSearchString )
endif
RETURN nil