Page 1 of 1

TMenu::DelItems

PostPosted: Fri Jan 05, 2018 3:50 pm
by AntoninoP
Hello,
In my program I see that TMenu::DelItems goes in infinite loop, I look the code, and I see:
Code: Select all  Expand view
METHOD DelItems() CLASS TMenu

   while Len( ::aMenuItems ) > 0
      ATail( ::aMenuItems ):End()  //Destroy()
   end

return nil

Someone has remove Destroy and has put End, The problem is that Destroy removes the item from aMenuItems, End does not do it.
In this way it calls End of the last item forever.
I Will change my calls, but I think it need to be fixed...
Antonino

Re: TMenu::DelItems

PostPosted: Fri Jan 05, 2018 8:58 pm
by cnavarro
Antonino:
Can you give a small example of how you use the method?

If you need use this method directly from a line of your code, use this modification in your TMenu class, and use ::DelITems( .F. )
Note that the End method calls the Destroy method
In any case, I will review its operation

Code: Select all  Expand view


METHOD DelItems( lEnd ) CLASS TMenu

   DEFAULT lEnd   := .T.
   while Len( ::aMenuItems ) > 0
      if lEnd
         ATail( ::aMenuItems ):End()
      else
         ATail( ::aMenuItems ):Destroy()
      endif
   end

return nil

 

Re: TMenu::DelItems

PostPosted: Sat Jan 06, 2018 11:12 am
by AntoninoP
After some tests I use a version like this:
Code: Select all  Expand view
proc MenuDelItems( oMenu )
   LOCAL i
   for i:=len(oMenu:aItems) to 1 step -1
      oMenu:DelItem(i)
   next
   oMenu:aItems := {}

PS. I do not have to hand code I recreated from memory