This message is to confirm my experience with the bug in TreeItemValue and that because I still got an answer from Dr. Claudio, I kindly ask Rathinagiri to analyze and approve the solution presented below:
All following appointed errors are based on SAMPLES\Controls\Tree\TREE_1\Demo.Prg as example and test:
- Error #1:
At current DOC (at least in 3.4.4) says we can use This.TreeItemValue but if we change demo for:
ITEM 'Expand Item' ACTION Form_1.Tree_1.Expand ( MsgDebug(This.TreeItemValue) )
It will return this error: MsgDebug(This.TreeItemValue) should displays the current value at Tree item.
This ID value could differs when is used ID (with ITEMIDS true and each due identification at all items) and when not used which it should return the tree item position at _HMG_aTreeMap.
- Error #2:
According DOC at current version, ITEMIDS is a Tree property clause to switch when using for these USER's ID instead item position but if we change demo for:
DEFINE TREE Tree_1 AT 10,10 WIDTH 200 HEIGHT 400 VALUE 156 ITEMIDS
It will return this error: Even trying with another syntax, error comes again:
Indication to fix these TREE bugs::
- h_tree.prg
- Reforced TreeItemGetHandle function to avoid unexpected values:
Code: Select all
Function TreeItemGetHandle ( ControlName , ParentForm , nItem ) LOCAL nPos, nID, ItemHandle := 0 LOCAL i := GetControlIndex( ControlName , ParentForm ) If i > 0 If _HMG_SYSDATA [ 9 ] [i] == .F. If nItem <= Len( _HMG_SYSDATA [ 138 ] ) // Pablo César April 27th nPos := nItem ItemHandle := _HMG_SYSDATA [7] [i] [ nPos ] // nPos Endif Else nID := nItem nPos := ASCAN ( _HMG_SYSDATA [25] [i] , nID ) // nID If nPos > 0 ItemHandle := _HMG_SYSDATA [7] [i] [ nPos ] Endif EndIf Endif Return ItemHandle
- Reforced _EndTree function to avoid unexpected values:
Code: Select all
Function _EndTree() LOCAL nPos _HMG_SYSDATA [ 7 ] [ _HMG_SYSDATA [ 179 ] ] := _HMG_SYSDATA [ 138 ] _HMG_SYSDATA [ 25 ] [ _HMG_SYSDATA [ 179 ] ] := _HMG_SYSDATA [ 139 ] If _HMG_SYSDATA [ 178 ] > 0 If _HMG_SYSDATA [ 259 ] == .F. TreeView_SelectItem ( _HMG_SYSDATA [ 180 ] , _HMG_SYSDATA [ 138 ] [ _HMG_SYSDATA [ 178 ] ] ) Else nPos := AScan ( _HMG_SYSDATA [ 139 ] , _HMG_SYSDATA [ 178 ] ) // Pablo César April 27th If nPos > 0 TreeView_SelectItem ( _HMG_SYSDATA [ 180 ] , _HMG_SYSDATA [ 138 ] [ nPos ] ) Else ShowError("ID "+AllTrim(Str(_HMG_SYSDATA [ 178 ]))+" as initial Tree Item Value, not found."+CRLF+"Program terminated.") Endif EndIf EndIf Return Nil
- Reforced TreeItemGetHandle function to avoid unexpected values:
- i_tree.ch
There are 4 ways to define TREE and the ITEMIDS clause has two ways that "will" confuse users because one way is with passing value and the other is not. I repeat: "will confuse" (in the future tense) because this option is new and apparently no one used before because otherwise would accuse the same error that I reported. So I decided to normalize (leaving as a SWITCH) the four TREE modes for: Standard Syntax, Alternate Syntax, Standard and Extended:Note that in two situations this was changed:Code: Select all
* Standard Syntax #xcommand DEFINE TREE <name> ; [ <dummy1: OF, PARENT> <parent> ] ; AT <row> , <col> ; [ WIDTH <width> ] ; [ HEIGHT <height> ] ; [ VALUE <value> ] ; [ FONT <fontname> ] ; [ SIZE <fontsize> ] ; [ <bold : BOLD> ] ; [ <italic : ITALIC> ] ; [ <underline : UNDERLINE> ] ; [ <strikeout : STRIKEOUT> ] ; [ TOOLTIP <tooltip> ] ; [ ON GOTFOCUS <gotfocus> ] ; [ ON CHANGE <change> ] ; [ ON LOSTFOCUS <lostfocus> ] ; [ ON DBLCLICK <dblclick> ] ; [ NODEIMAGES <aImgNode> [ ITEMIMAGES <aImgItem> ] [ <noBut: NOROOTBUTTON> ]]; [ <itemids : ITEMIDS> ] ; [ HELPID <helpid> ] ; [ <NoTrans : NOTRANSPARENT> ] ; [ ON EXPAND <OnExpand> ] ; [ ON COLLAPSE <OnCollapse> ] ; [ BACKCOLOR <aBackColor> ] ; [ FONTCOLOR <aFontColor> ] ; [ DYNAMICBACKCOLOR <DynamicBackColor> ] ; [ DYNAMICFORECOLOR <DynamicForeColor> ] ; [ DYNAMICFONT <DynamicFont> ] ; =>; _DefineTree ( <"name"> , <"parent"> , <row> , <col> , <width> , <height> , <{change}> , <tooltip> , <fontname> , <fontsize> , <{gotfocus}> , <{lostfocus}> , <{dblclick}> , .f. , <value> , <helpid>, <aImgNode>, <aImgItem>, <.noBut.> ,<.bold.>, <.italic.>, <.underline.>, <.strikeout.> , <.itemids.> , Nil , <.NoTrans.> , <{OnExpand}> , <{OnCollapse}> , <aBackColor> , <aFontColor> , <DynamicBackColor> , <DynamicForeColor> , <DynamicFont> ) * Alternate Syntax #xcommand DEFINE TREE <name> ; [ PARENT <parent> ] ; ROW <row> ; COL <col> ; [ WIDTH <width> ] ; [ HEIGHT <height> ] ; [ VALUE <value> ] ; [ FONTNAME <fontname> ] ; [ FONTSIZE <fontsize> ] ; [ FONTBOLD <bold> ] ; [ FONTITALIC <italic> ] ; [ FONTUNDERLINE <underline> ] ; [ FONTSTRIKEOUT <strikeout> ] ; [ TOOLTIP <tooltip> ] ; [ ONGOTFOCUS <gotfocus> ] ; [ ONCHANGE <change> ] ; [ ONLOSTFOCUS <lostfocus> ] ; [ ONDBLCLICK <dblclick> ] ; [ NODEIMAGES <aImgNode> ] ; [ ITEMIMAGES <aImgItem> ] ; [ ROOTBUTTON <rootbutton> ] ; [ <itemids : ITEMIDS> ] ; [ HELPID <helpid> ] ; [ TRANSPARENT <Trans> ] ; [ ONEXPAND <OnExpand> ] ; [ ONCOLLAPSE <OnCollapse> ] ; [ BACKCOLOR <aBackColor> ] ; [ FONTCOLOR <aFontColor> ] ; [ DYNAMICBACKCOLOR <DynamicBackColor> ] ; [ DYNAMICFORECOLOR <DynamicForeColor> ] ; [ DYNAMICFONT <DynamicFont> ] ; =>; _DefineTree ( <"name"> , <"parent"> , <row> , <col> , <width> , <height> , <{change}> , <tooltip> , <fontname> , <fontsize> , <{gotfocus}> , <{lostfocus}> , <{dblclick}> , .f. , <value> , <helpid>, <aImgNode>, <aImgItem>, .f. ,<.bold.>, <.italic.>, <.underline.>, <.strikeout.> , <.itemids.> , <rootbutton> , <.Trans.> , <{OnExpand}> , <{OnCollapse}> , <aBackColor> , <aFontColor> , <DynamicBackColor> , <DynamicForeColor> , <DynamicFont> ) #xcommand NODE <text> [ IMAGES <aImage> ] [ ID <id> ]; =>; _DefineTreeNode (<text>, <aImage> , <id> ) #xcommand DEFINE NODE <text> [ IMAGES <aImage> ] [ ID <id> ] ; =>; _DefineTreeNode (<text>, <aImage> , <id> ) #xcommand END NODE ; =>; _EndTreeNode() #xcommand TREEITEM <text> [ IMAGES <aImage> ] [ ID <id> ] ; => ; _DefineTreeItem (<text>, <aImage> , <id> ) #xcommand END TREE ; => ; _EndTree() /////////////////////////////////////////////////////////////////////////////// // SPLITBOX VERSION /////////////////////////////////////////////////////////////////////////////// * Standard #xcommand DEFINE TREE <name> ; [ <dummy1: OF, PARENT> <parent> ] ; [ WIDTH <width> ] ; [ HEIGHT <height> ] ; [ VALUE <value> ] ; [ FONT <fontname> ] ; [ SIZE <fontsize> ] ; [ <bold : BOLD> ] ; [ <italic : ITALIC> ] ; [ <underline : UNDERLINE> ] ; [ <strikeout : STRIKEOUT> ] ; [ TOOLTIP <tooltip> ] ; [ ON GOTFOCUS <gotfocus> ] ; [ ON CHANGE <change> ] ; [ ON LOSTFOCUS <lostfocus> ] ; [ ON DBLCLICK <dblclick> ] ; [ <itemids : ITEMIDS> ] ; [ HELPID <helpid> ] ; [ NODEIMAGES <aImgNode> [ ITEMIMAGES <aImgItem> ] [ <noBut: NOROOTBUTTON> ]]; [ <break: BREAK> ] ; [ <NoTrans : NOTRANSPARENT> ]; [ ON EXPAND <OnExpand> ] ; [ ON COLLAPSE <OnCollapse> ] ; [ BACKCOLOR <aBackColor> ] ; [ FONTCOLOR <aFontColor> ] ; [ DYNAMICBACKCOLOR <DynamicBackColor> ] ; [ DYNAMICFORECOLOR <DynamicForeColor> ] ; [ DYNAMICFONT <DynamicFont> ] ; =>; _DefineTree ( <"name"> , <"parent"> , , , <width> , <height> , <{change}> , <tooltip> , <fontname> , <fontsize> , <{gotfocus}> , <{lostfocus}> , <{dblclick}> , <.break.> , <value> , <helpid>, <aImgNode>, <aImgItem>, <.noBut.> ,<.bold.>, <.italic.>, <.underline.>, <.strikeout.> , <.itemids.> , Nil , <.NoTrans.> , <{OnExpand}> , <{OnCollapse}> , <aBackColor> , <aFontColor> , <DynamicBackColor> , <DynamicForeColor> , <DynamicFont> ) * Extended #xcommand DEFINE TREE <name> ; [ PARENT <parent> ] ; [ WIDTH <width> ] ; [ HEIGHT <height> ] ; [ VALUE <value> ] ; [ FONTNAME <fontname> ] ; [ FONTSIZE <fontsize> ] ; [ FONTBOLD <bold> ] ; [ FONTITALIC <italic> ] ; [ FONTUNDERLINE <underline> ] ; [ FONTSTRIKEOUT <strikeout> ] ; [ TOOLTIP <tooltip> ] ; [ ONGOTFOCUS <gotfocus> ] ; [ ONCHANGE <change> ] ; [ ONLOSTFOCUS <lostfocus> ] ; [ ONDBLCLICK <dblclick> ] ; [ <itemids : ITEMIDS> ] ; [ HELPID <helpid> ] ; [ NODEIMAGES <aImgNode> ] ; [ ITEMIMAGES <aImgItem> ] ; [ ROOTBUTTON <rootbutton> ] ; [ BREAK <break> ] ; [ TRANSPARENT <Trans> ] ; [ ONEXPAND <OnExpand> ] ; [ ONCOLLAPSE <OnCollapse> ] ; [ BACKCOLOR <aBackColor> ] ; [ FONTCOLOR <aFontColor> ] ; [ DYNAMICBACKCOLOR <DynamicBackColor> ] ; [ DYNAMICFORECOLOR <DynamicForeColor> ] ; [ DYNAMICFONT <DynamicFont> ] ; =>; _DefineTree ( <"name"> , <"parent"> , , , <width> , <height> , <{change}> , <tooltip> , <fontname> , <fontsize> , <{gotfocus}> , <{lostfocus}> , <{dblclick}> , <.break.> , <value> , <helpid>, <aImgNode>, <aImgItem>, .f. ,<.bold.>, <.italic.>, <.underline.>, <.strikeout.> , <.itemids.> , <rootbutton> , <.Trans.> , <{OnExpand}> , <{OnCollapse}> , <aBackColor> , <aFontColor> , <DynamicBackColor> , <DynamicForeColor> , <DynamicFont> )
[ ITEMIDS <itemids> ]
For this:
[ <itemids : ITEMIDS> ] as corrected.
- h_windows.prg
As I was asked to Dr. Claudio, I was able to prove for myself that the value error of the TREE item comes wrongly at Expand and Collapse events and because I also see no reason to annul its value. So I decided to disable the lines where the _HMG_This_TreeItem_Value is wrongly assigned with NIL value:Please search for * _HMG_This_TreeItem_Value that I already disable it.Code: Select all
* Tree Processing ..................................... if _HMG_SYSDATA [1] [i] = "TREE" * Tree LostFocus ............................. If GetNotifyCode ( lParam ) = NM_KILLFOCUS _DoControlEventProcedure ( _HMG_SYSDATA [10] [i] , i ) Return 0 EndIf * Tree GotFocus .............................. If GetNotifyCode ( lParam ) = NM_SETFOCUS VirtualChildControlFocusProcess ( _HMG_SYSDATA [3] [i] , _HMG_SYSDATA [4] [i] ) _DoControlEventProcedure ( _HMG_SYSDATA [ 11 ] [i] , i ) Return 0 EndIf * Tree Change ................................ If GetNotifyCode ( lParam ) = TVN_SELCHANGED _DoControlEventProcedure ( _HMG_SYSDATA [ 12 ] [i] , i ) Return 0 EndIf * Tree Double Click ......................... If GetNotifyCode ( lParam ) == NM_DBLCLK _DoControlEventProcedure ( _HMG_SYSDATA [ 16 ] [i] , i ) Return 0 EndIf * Tree OnExpand and OnCollapse ......................... (Dr. Claudio Soto, July 2014) IF GetNotifyCode ( lParam ) == TVN_ITEMEXPANDING /*TVN_ITEMEXPANDED*/ _HMG_ret := NOTIFY_TREEVIEW_ITEMEXPAND ( lParam ) * _HMG_This_TreeItem_Value := NIL If _HMG_SYSDATA [9] [i] == .F. _HMG_This_TreeItem_Value := ASCAN ( _HMG_SYSDATA [7] [i], _HMG_ret [2] ) Else _HMG_This_TreeItem_Value := TREEITEM_GETID ( _HMG_SYSDATA [3] [i], _HMG_ret [2] ) EndIf IF _HMG_ret [1] == TVE_EXPAND _DoControlEventProcedure ( _HMG_SYSDATA [ 17 ] [i] [1], i ) * _HMG_This_TreeItem_Value := NIL Return 0 ENDIF IF _HMG_ret [1] == TVE_COLLAPSE _DoControlEventProcedure ( _HMG_SYSDATA [ 17 ] [i] [2], i ) * _HMG_This_TreeItem_Value := NIL Return 0 ENDIF ENDIF * Tree Dynamic ForeColor, BackColor and Font ......................... (Dr. Claudio Soto, July 2014) IF GetNotifyCode (lParam) == NM_CUSTOMDRAW IF ValType (_HMG_SYSDATA [40] [i] [1]) == "B" .OR. ; // DynamicBackColor ValType (_HMG_SYSDATA [40] [i] [2]) == "B" .OR. ; // DynamicForeColor ValType (_HMG_SYSDATA [40] [i] [3]) == "B" // DynamicFont SetNewBehaviorWndProc (.T.) // ADD2, December 2014 r := TREEVIEW_CUSTOMDRAW_GetAction ( lParam ) if r <> -1 Return R // return CDRF_NOTIFYITEMDRAW or CDRF_DODEFAULT endif * _HMG_This_TreeItem_Value := NIL _HMG_ret := ASCAN ( _HMG_SYSDATA [7] [i], TREEVIEW_CUSTOMDRAW_GETITEMHANDLE (lParam) ) IF _HMG_ret > 0 If _HMG_SYSDATA [9] [i] == .F. _HMG_This_TreeItem_Value := _HMG_ret ELSE _HMG_This_TreeItem_Value := _HMG_SYSDATA [25] [i] [ _HMG_ret ] EndIf Return _DoTreeCustomDraw ( i , lParam ) // return CDRF_NEWFONT ENDIF ENDIF ENDIF
- h_init.prg
There is no sense to create a _HMG_This_TreeItem_Value with NIL value because TREE ID always start at least with one item.
So the initial value must to be to 1 then the error disappeared when I set the TREE.
Originally it was: And changed by this:Code: Select all
PUBLIC _HMG_This_TreeItem_Value := 1 //ADD
I would like you Rathinagiri to give me a please return about this.