Faceți căutări pe acest blog

joi, 5 februarie 2015

Typing characters programmatically, by invoking the keypress event

Unlike other events (click or interactivechange), if keypress is programmatically invoked, the code is executed 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.

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

See
http://www.tek-tips.com/faqs.cfm?fid=7702
Related links
[1] "Typing" characters programatically (2)
[2] "Typing" characters programatically (3)
[3] "Typing" characters programatically (4)

Niciun comentariu:

Trimiteți un comentariu