Faceți căutări pe acest blog

duminică, 20 august 2017

Invalid keys in a TreeView Control

Each node of a TreeView has a key. The key is a string and must be unique [2].
Accidentally I discovered some unacceptable values for this key [3].

Generally, are rejected values that resembles a number:
- Integer literals, like '1'
- Integer literals followed by a period, like '1.'
- Integer literals preceded or folowed by a symbol sign, like '+1' or '1-'
- Numbers with commas between its digits, like '1,' ; '1,1,1' ; '1.,' or '.1,'
- Integer literals preceded or folowed by Space, Tabe or CR

Please try following example.



PUBLIC ofrm
ofrm=CREATEOBJECT("MyForm")
ofrm.show()

DEFINE CLASS MyForm as Form
      autocenter = .T.
      ADD OBJECT teeview as olecontrol WITH oleclass = 'COMCtl.treectrl', width = 300,height = 350
      PROCEDURE init
            LOCAL lcRoot,loRoot
            lcRoot='Root'
            loRoot = thisform.TeeView.Nodes.Add(, 1, m.lcRoot,'Root node')
            loRoot.Expanded = .T.
            * Rejected
            thisform.AddNode(m.lcRoot,'1')
            thisform.AddNode(m.lcRoot,'1.')
            thisform.AddNode(m.lcRoot,'1,')
            thisform.AddNode(m.lcRoot,'+1')
            thisform.AddNode(m.lcRoot,'1.,')
            thisform.AddNode(m.lcRoot,'.1,')
            thisform.AddNode(m.lcRoot,'-1')
            thisform.AddNode(m.lcRoot,'1+')
            thisform.AddNode(m.lcRoot,'1-')
            thisform.AddNode(m.lcRoot,' 1')
            thisform.AddNode(m.lcRoot,'1 ')
            thisform.AddNode(m.lcRoot,CHR(13) + '1')
            thisform.AddNode(m.lcRoot,CHR(9) + '1')
            thisform.AddNode(m.lcRoot,'1,1,1,1')
           
            * Accepted
            thisform.AddNode(m.lcRoot,CHR(13))
            thisform.AddNode(m.lcRoot,CHR(9))
            thisform.AddNode(m.lcRoot,'1 1')
            thisform.AddNode(m.lcRoot,'1E')
            thisform.AddNode(m.lcRoot,'1+1')
      ENDPROC
      PROCEDURE AddNode
            LPARAMETERS lcRoot, lcKey
            LOCAL loErr as Exception
            TRY
                  thisform.TeeView.Nodes.Add(m.lcRoot, 4, m.lcKey,m.lcKey)
            CATCH TO loErr
                  ACTIVATE SCREEN
                  ? m.lcKey, loErr.ErrorNo , loErr.Message
            ENDTRY
      ENDPROC
ENDDEFINE


Bibliography
[1] TreeView Control
[2] Key Property
[3] The code the lead me to these conclusions

vineri, 18 august 2017

Easter eggs (3)

Peculiarity

I can't catch the 3+4+5. I do any combination of two, i.e. 3+4, 3+5 and 4+5, but not all three of them.
Please try the next demo


CLEAR
PUBLIC ofrm
ofrm = CREATEOBJECT("myform")
ofrm.show()

DEFINE CLASS myform as form
      Autocenter = .T.
      l3 = .F. && .T. while 3 is down (pressed)
      l4 = .F. && .T. while 4 is down (pressed)
      l5 = .F. && .T. while 5 is down (pressed)
      ADD OBJECT txt1 as textbox
      ADD OBJECT cmd as commandbutton WITH top = 50
      PROCEDURE init
            UNBINDEVENTS(This.hwnd)
            BINDEVENT(This.hwnd,0x0100,This,"detectkeydown")
            BINDEVENT(This.hwnd,0x0101,This,"detectkeyup")
      ENDPROC
      PROCEDURE detectkeydown
            LPARAMETERS p1,p2,p3,p4
            * p3 = Virtual-key code
            IF p3 = 0x33 && 3 is pressed
                  This.l3 = .T.
            ENDIF
            IF p3 = 0x34 && 4 is pressed
                  This.l4 = .T.
            ENDIF
            IF p3 = 0x35 && 5 is pressed
                  This.l5 = .T.
            ENDIF
            IF This.l3 AND This.l4 AND This.l5
                  ACTIVATE SCREEN
                  ? 'Bingo!'
                  ? 'An 3+4+5 occures'
            ENDIF
                  ACTIVATE SCREEN
            ?This.l3 ,This.l4 ,This.l5
      ENDPROC
      PROCEDURE detectkeyup
            LPARAMETERS p1,p2,p3,p4
            * p3 = Virtual-key code
            IF p3 = 0x33 && 3 is released
                  This.l3 = .F.
            ENDIF
            IF p3 = 0x34 && 4 is released
                  This.l4 = .F.
            ENDIF
            IF p3 = 0x35 && 5 is released
                  This.l5 = .F.
            ENDIF
      ENDPROC
ENDDEFINE

  Oddly, the keys from the numeric keypad behaves normally.



CLEAR
PUBLIC ofrm
ofrm = CREATEOBJECT("myform")
ofrm.show()

DEFINE CLASS myform as form
      Autocenter = .T.
      l3 = .F. && .T. while 3 is down (pressed)
      l4 = .F. && .T. while 4 is down (pressed)
      l5 = .F. && .T. while 5 is down (pressed)
      ADD OBJECT txt1 as textbox
      ADD OBJECT cmd as commandbutton WITH top = 50
      PROCEDURE init
            UNBINDEVENTS(This.hwnd)
            BINDEVENT(This.hwnd,0x0100,This,"detectkeydown")
            BINDEVENT(This.hwnd,0x0101,This,"detectkeyup")
      ENDPROC
      PROCEDURE detectkeydown
            LPARAMETERS p1,p2,p3,p4
            * p3 = Virtual-key code
            IF p3 = 0x63 && 3 is pressed
                  This.l3 = .T.
            ENDIF
            IF p3 = 0x64 && 4 is pressed
                  This.l4 = .T.
            ENDIF
            IF p3 = 0x65 && 5 is pressed
                  This.l5 = .T.
            ENDIF
            IF This.l3 AND This.l4 AND This.l5
                  ACTIVATE SCREEN
                  ? 'Bingo!'
                  ? 'An 3+4+5 occures'
            ENDIF
                  ACTIVATE SCREEN
            ?This.l3 ,This.l4 ,This.l5
      ENDPROC
      PROCEDURE detectkeyup
            LPARAMETERS p1,p2,p3,p4
            * p3 = Virtual-key code
            IF p3 = 0x63 && 3 is released
                  This.l3 = .F.
            ENDIF
            IF p3 = 0x64 && 4 is released
                  This.l4 = .F.
            ENDIF
            IF p3 = 0x65 && 5 is released
                  This.l5 = .F.
            ENDIF
      ENDPROC
ENDDEFINE