Unlike other events (click or interactivechange), if keypress is simply invoked, it is triggered but the characters are not "typed".
But with a little trick, this can be surpassed.
Add a third parameter (logical) in the keypress event .
If this third parameter is .T., then call DODEFAULT() followed by =This.Value.
DEFINE CLASS MyForm as Form
ADD OBJECT txt as MyText
ADD OBJECT cmd as CommandButton WITH left=150,Caption='Select any row from grid and click',Autosize=.T.
ADD OBJECT grd as grid WITH top=50
PROCEDURE init
LOCAL lni
* Preparing the grid
CREATE CURSOR cChar (cChar C(10))
FOR lni=1 TO 5
INSERT INTO cChar values (CHR(64+m.lni))
NEXT
INSERT INTO cChar values ('Two words')
GO TOP
This.grd.RecordSource='cChar'
This.grd.column1.width=100
ENDPROC
PROCEDURE cmd.click
LOCAL lni,lcStr
lcStr=ALLTRIM(cChar.cChar)
FOR lni=1 TO LEN(m.lcStr)
ThisForm.txt.Keypress(ASC(SUBSTR(m.lcStr,m.lni,1)),0,.T.)
NEXT
ENDPROC
ENDDEFINE
*********************
* Text box class
*********************
DEFINE CLASS MyText as TextBox
PROCEDURE keypress
LPARAMETERS nKey,nShift,lraised
IF lraised
DODEFAULT(nKey,nShift)
=This.value
ENDIF
ENDPROC
ENDDEFINE[/code]
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.