TreeItemValue bug

Moderator: Rathinagiri

User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

TreeItemValue bug

Post by Pablo César »

Hi all,

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:
    Screen199.png
    Screen199.png (18.51 KiB) Viewed 12233 times
    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:
    Screen201.png
    Screen201.png (7.06 KiB) Viewed 12233 times
    Even trying with another syntax, error comes again:
    Screen200.png
    Screen200.png (11.54 KiB) Viewed 12233 times
 
Indication to fix these TREE bugs::
  1. h_tree.prg
    1. 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
    2. 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
  2. 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:

    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>  )
    Note that in two situations this was changed:
    [ ITEMIDS <itemids> ]
    For this:
    [ <itemids : ITEMIDS> ] as corrected.
     
  3. 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:

    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
    Please search for * _HMG_This_TreeItem_Value that I already disable it.
    Screen202.png
    Screen202.png (38.67 KiB) Viewed 12233 times
     
  4. 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:
    Screen203.png
    Screen203.png (65.24 KiB) Viewed 12233 times
    And changed by this:

    Code: Select all

    PUBLIC _HMG_This_TreeItem_Value   := 1     //ADD
I tested all TREE samples with new patch and all seems working properly.

I would like you Rathinagiri to give me a please return about this.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
srvet_claudio
Posts: 2193
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: TreeItemValue bug

Post by srvet_claudio »

Is not a bug, This.TreeItemValue is only available inside some events, see the doc.
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Re: TreeItemValue bug

Post by Pablo César »

Hi Claudio,
srvet_claudio wrote: Thu Apr 27, 2017 11:08 pm Is not a bug, This.TreeItemValue is only available inside some events, see the doc.
So, why this code at SAMPLES are with breaking with ERROR ?

Code: Select all

#include "hmg.ch"

Function main()

	DEFINE WINDOW Form_1 ;
		AT 0,0 ;
		WIDTH 640 ;
		HEIGHT 480 ;
		TITLE 'TreeView Sample' ;
		MAIN 

		DEFINE MAIN MENU
			POPUP '&File'
				ITEM 'Get Tree Value' ACTION MsgInfo( Str ( Form_1.Tree_1.Value ) ) 
				ITEM 'Set Tree Value' ACTION Form_1.Tree_1.Value := val(inputbox('',''))
				ITEM 'Collapse Item' ACTION Form_1.Tree_1.Collapse ( val(inputbox('','') ) )
				ITEM 'Expand Item' ACTION Form_1.Tree_1.Expand ( MsgDebug(This.TreeItemValue) )
			END POPUP
		END MENU

		DEFINE CONTEXT MENU 
			ITEM 'About'				ACTION MsgInfo ("Free GUI Library For Harbour","HMG Tree Demo") 
		END MENU

		DEFINE TREE Tree_1 AT 10,10 WIDTH 200 HEIGHT 400 VALUE 15 ITEMIDS

			NODE 'Item 1' 
				TREEITEM 'Item 1.1'
				TREEITEM 'Item 1.2' ID 999
				TREEITEM 'Item 1.3'
			END NODE

			NODE 'Item 2'

				TREEITEM 'Item 2.1'

				NODE 'Item 2.2'
					TREEITEM 'Item 2.2.1'
					TREEITEM 'Item 2.2.2'
					TREEITEM 'Item 2.2.3'
					TREEITEM 'Item 2.2.4'
					TREEITEM 'Item 2.2.5'
					TREEITEM 'Item 2.2.6'
					TREEITEM 'Item 2.2.7'
					TREEITEM 'Item 2.2.8'
				END NODE

				TREEITEM 'Item 2.3'

			END NODE

			NODE 'Item 3'
				TREEITEM 'Item 3.1'
				TREEITEM 'Item 3.2'

				NODE 'Item 3.3'
					TREEITEM 'Item 3.3.1'
					TREEITEM 'Item 3.3.2'
				END NODE

			END NODE

		END TREE

		@ 10,400 BUTTON Button_1 ;
		CAPTION 'Delete Item' ;
		ACTION Form_1.Tree_1.DeleteItem( Form_1.Tree_1.Value ) ;
		WIDTH 150

		@ 40,400 BUTTON Button_2 ;
		CAPTION 'Delete All Items' ;
		ACTION Form_1.Tree_1.DeleteAllItems ;
		WIDTH 150

		@ 70,400 BUTTON Button_3 ;
		CAPTION 'Get Item Count' ;
		ACTION MsgInfo ( Str ( Form_1.Tree_1.ItemCount ) ) ;
		WIDTH 150

		@ 100,400 BUTTON Button_4 ;
		CAPTION 'DeleteAll / Add Test' ;
		ACTION AddItemTest() ;
		WIDTH 150

		@ 130,400 BUTTON Button_5 ;
		CAPTION 'Set Value' ;
		ACTION Form_1.Tree_1.Value := 1 ;
		WIDTH 150

		@ 160,400 BUTTON Button_6 ;
		CAPTION 'Get Item' ;
		ACTION MsgInfo ( Form_1.Tree_1.Item ( Form_1.Tree_1.Value ) ) ;
		WIDTH 150

		@ 190,400 BUTTON Button_7 ;
		CAPTION 'Set Item' ;
		ACTION Form_1.Tree_1.Item( Form_1.Tree_1.Value ) := 'New Item text' ;
		WIDTH 150

	END WINDOW

	ACTIVATE WINDOW Form_1

Return

Function AddItemTest()

	Form_1.Tree_1.DeleteAllItems

	Form_1.Tree_1.AddItem( 'New Root Item 1'   , 0 )

	Form_1.Tree_1.AddItem( 'New Item 1.1' , 1 )
	Form_1.Tree_1.AddItem( 'New Item 1.2' , 1 )
	Form_1.Tree_1.AddItem( 'New Item 1.3' , 1 )

	Form_1.Tree_1.AddItem( 'New Root Item 2'   , 0 )

	Form_1.Tree_1.AddItem( 'New Item 2.1' , 5 )
	Form_1.Tree_1.AddItem( 'New Item 2.2' , 5 )
	Form_1.Tree_1.AddItem( 'New Item 2.3' , 5 )

	Form_1.Tree_1.AddItem( 'New Item 1.4' , 1 )
	Form_1.Tree_1.AddItem( 'New Item 1.4.1' , 5 )

Return Nil
I sorry to say but I think I have explained very well and with rich informations to receive this your response. :shock:
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
srvet_claudio
Posts: 2193
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: TreeItemValue bug

Post by srvet_claudio »

I'm sorry Pablo but there is not much to add to what I already expressed, outside the some events This.TreeItemValue is nil and this behavoir is right because is not available.

Here:
Form_1.Tree_1.Expand ( MsgDebug(This.TreeItemValue) )

You use This.TreeItemValue with the Expand method, bud This.TreeItemValue is valid inside of ON EXPAND event.
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Re: TreeItemValue bug

Post by Pablo César »

srvet_claudio wrote: Fri Apr 28, 2017 12:45 am I'm sorry Pablo but there is not much to add to what I already expressed, outside the some events This.TreeItemValue is nil and this behavoir is right because is not available.

Here:
Form_1.Tree_1.Expand ( MsgDebug(This.TreeItemValue) )

You use This.TreeItemValue with the Expand method, bud This.TreeItemValue is valid inside of ON EXPAND event.
But before I changed, these values were always NIL and by the current HMG code it's forcing to NIL. Why to force ? :?

I will prepare a simple to demonstrate my frustation with original code at expandig and collapse nodes.
When I click to "+" or to "-", images are not duly displayed. What I want is to displaying an open folder picture when is expading event.
And display a closed folder when is collapsed. I have check and pretty sure of event is working well with these indicated codes.

I am in my third day in this and I wish to be approved because is working for me now with these patches.
Otherwise I will need to create my own tree, my ownevent, my own include file. So, why this ?

Redarding ITEMIDS clause must it working and for me these indicated patches are pretty working well.

Is that what I want. To tell me that I am wrong and let us known what is wrong in these indicated patches.

Is it posible ?
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: TreeItemValue bug

Post by edk »

Pablo César wrote: Fri Apr 28, 2017 10:58 am When I click to "+" or to "-", images are not duly displayed. What I want is to displaying an open folder picture when is expading event.
And display a closed folder when is collapsed.
Pablo, maybe try this way:

Code: Select all

ON EXPAND Form_1.Tree_1.ImageIndex(This.TreeItemValue):={1,1};
ON COLLAPSE Form_1.Tree_1.ImageIndex(This.TreeItemValue):={0,1};
Bez tytułu.png
Bez tytułu.png (15.76 KiB) Viewed 12171 times
You can also make different icons for expanded and selected node:

In this case you should add new image for expanded node:

Code: Select all

Form_1.Tree_1.AddImage:="folder_expand.gif"
ON Expand change to:

Code: Select all

ON EXPAND Form_1.Tree_1.ImageIndex(This.TreeItemValue):={4,1};
Generally tree images are stored under indexes:
NODEIMAGES unSelected = 0
NODEIMAGES Selected = 1
ITEMIMAGES unSelected = 2
ITEMIMAGES Selected = 3

Each other image added will receive another index numer.

for example:

Code: Select all

NODEIMAGES { "folder.gif", "folder_page.gif" }; 
ITEMIMAGES { "Page.gif",   "page_next.gif"   }; 
Form_1.Tree_1.AddImage:="folder_expand.gif"

"folder.gif" = 0
"folder_page.gif" = 1
"Page.gif" = 2 
"page_next.gif" = 3
"folder_expand.gif" = 4
Bez tytułu2.png
Bez tytułu2.png (14.98 KiB) Viewed 12149 times
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Re: TreeItemValue bug

Post by Pablo César »

Hi Edward,

The solution I have already found and I have not any doubt about it.
Thank you for your indication and interest to help me. But as I have already explained the problem it is others things.

In summary, what I maintain is: wrong attrib at HMG event + bad clause used for ITEMIDS + bad function to locate ID + _HMG_This_TreeItem_Value wrong declared value.

I will explain in the practice, probably I will get better sucess to make me understand by it.

I attach the following demos and please make the favor you Edward, you Claudio and who else can be so kind into test it and revert with your opinions if I am wrong or not in what I'm saying...

Here are two executables:

-One with name Demo2.exe and have it been builded with 3.4.4 originally (not patched).
-Another is Demo2_Patched.exe and have it been builded with already patched in the HMG core. In other words: with HMG altered in the code of TREE which demands with according my previous indication (pls read my first msg attentively).

Remark: When I said patched, is to be applied all my recomendations.
 
TREE_2.rar
Demos pack for testing proposes
(2.42 MiB) Downloaded 314 times
 
Please compare the behaviour of both executables files when you click on "+" and "-". You will see the picture doesn't change. :|
I know there is a way to forces it to the due image changing. But you will note that Demo2.exe it's not working properly. Check always node's IMAGE and STATUSBAR to reach what I am saying.

Please somebody let me know if I am wrong or not.

Thank you Edward for your interest and thanks to anybody who is interested to solve TREE problem too. But need thecnical feedback (with details in what I am doing wrong) and what can be do for improving this problem in TREE value.

Sorry if my words in English appear to be repeated. My English is not so good. But I hope that in practice (in code language) it can facilitate understanding.

Wating for yours comments gentlemen.
Last edited by Pablo César on Fri Apr 28, 2017 1:37 pm, edited 4 times in total.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Re: TreeItemValue bug

Post by Pablo César »

Hi all,

Please also note at executables running for test, that when we click on the IMAGE node, this changes ok but NOT when we click on "+" or at "-'. :|

PS.: If is not any differance behaviour at executables running at yours, I will attach a video to prove that in my pc (Windows 7 32bits) are different. Pls let me know if this will be needed.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
serge_girard
Posts: 3161
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: TreeItemValue bug

Post by serge_girard »

Hi Pablo,

I ran both and only statusbar is different! One says 8 On Change and the other NIL
Images are OK.
Serge
There's nothing you can do that can't be done...
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Re: TreeItemValue bug

Post by Pablo César »

Thank you Serge for you feeding back. It's what I wanted to know.

Images are not changing in this example, because I not applied the Edward suggestions.
This is ok, for me because I can drive this thru the same value which is being displayed at STATUSBAR. But this value MUST be correct value. Andt how to make it right when these events attrib wrongly the value for TreeItemValue ? That's my main questioning to Claudio. Probably I need to write in Spanish to make me understanding... :oops: (As somebody said: I know nothing... :lol: :lol: My English is so bad).

TreeItemValue can not be NIL ! Am I right ?
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
Post Reply