vgulielmus
Programmer
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.
In the keypress event I added a third parameter (logical); if this third parameter is .T., then I called DODEFAULT().
There are some limitations, but the need for KEYBOARD command is decreased.
Interesting, though when the textbox got the focus, this characters are lost. Hm...
PUBLIC ofrm
ofrm=CREATEOBJECT("MyForm")
ofrm.show()
DEFINE CLASS MyForm as Form
*********************
* Text box class
*********************
DEFINE CLASS MyText as TextBox
But with a little trick, this can be surpassed.
In the keypress event I added a third parameter (logical); if this third parameter is .T., then I called DODEFAULT().
There are some limitations, but the need for KEYBOARD command is decreased.
Interesting, though when the textbox got the focus, this characters are lost. Hm...
PUBLIC ofrm
ofrm=CREATEOBJECT("MyForm")
ofrm.show()
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
PROCEDURE cmd.click
ENDDEFINEADD 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 ('Two words')
GO TOP
This.grd.RecordSource='cChar'
This.grd.column1.width=100
ENDPROC* Preparing the grid
CREATE CURSOR cChar (cChar C(10))
FOR lni=1 TO 5
INSERT INTO cChar values (CHR(64+m.lni))
NEXTINSERT INTO cChar values ('Two words')
GO TOP
This.grd.RecordSource='cChar'
This.grd.column1.width=100
PROCEDURE cmd.click
LOCAL lni,lcStr
lcStr=ALLTRIM(cChar.cChar)
FOR lni=1 TO LEN(m.lcStr)
ENDPROClcStr=ALLTRIM(cChar.cChar)
FOR lni=1 TO LEN(m.lcStr)
ThisForm.txt.Keypress(ASC(SUBSTR(m.lcStr,m.lni,1)),0,.T.)
NEXT*********************
* Text box class
*********************
DEFINE CLASS MyText as TextBox
PROCEDURE keypress
ENDDEFINELPARAMETERS nKey,nShift,lraised
IF lraised
ENDPROCIF lraised
DODEFAULT(nKey,nShift)
ENDIF