Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I type characters programmatically, by invoking the keypress event

Classes and Objects

How can I type characters programmatically, by invoking the keypress event

by  vgulielmus  Posted    (Edited  )
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.

[code Foxpro]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
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]

Vilhelm-Ion Praisach
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top