FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index All products support Creazione menu a runtime
Posts: 90
Joined: Wed Nov 07, 2007 08:56 AM
Creazione menu a runtime
Posted: Wed May 21, 2014 04:38 PM
Ciao a tutti,

ho riscontrato un problema costruendo un menu a runtime.

Piccolo esempio: ogni volta che cliccate su test il programma dovrebbe ricreare il menu. Se controllate con il gestione attivitĂ  vedrete che il numero di GDI objects utilizzati incrementa ogni volta di 20 unitĂ  senza mai liberarsi. Togliendo il riferimento all'immagine invece rimane invariato.

Visto che uso una versione di fivewin vecchia, qualcuno può provare sull'ultima se il problema persiste?

Code (fw): Select all Collapse
#include "FiveWin.ch"
static oWnd
static oSubMenu
//----------------------------------------------------------------------------//

function Main()
   DEFINE WINDOW oWnd TITLE "Test" MENU BuildMenu()
   @ 2, 2 BUTTON "Test" SIZE 120, 25 OF oWnd ACTION TestMenu()
   ACTIVATE WINDOW oWnd
return nil

//----------------------------------------------------------------------------//

function BuildMenu()
   local oMenu, oItem, n
   MENU oMenu
      MENUITEM "Test"
      MENU oSubMenu
         FOR n := 1 TO 20
            MENUITEM oItem PROMPT Str(n) ACTION ( MsgInfo("Any action!") ) FILE "c:\fwh\bitmaps\16x16\bitmap.bmp" OF oSubMenu
         NEXT
      ENDMENU
   ENDMENU
return oMenu

//----------------------------------------------------------------------------//

function TestMenu()
   local oItem, n
   oSubMenu:DelItems()
   FOR n := 1 TO 20
      oSubMenu:Add(TMenuItem():New(Str(n),,,.T.,{||MsgInfo("Any action!")},"c:\fwh\bitmaps\16x16\bitmap.bmp",),.T.)
   NEXT
return

//----------------------------------------------------------------------------//
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Creazione menu a runtime
Posted: Wed May 21, 2014 04:44 PM
Patrizio,

Please change Class TMenuItem Method Destroy this way:

Code (fw): Select all Collapse
METHOD Destroy() CLASS TMenuItem

   local nAt := AScan( ::oMenu:aItems,;
                       { | oItem | oItem:nId == ::nId } )
   local nResult                     

   if ValType( ::bAction ) == "O"
      ::bAction:End()
   endif

   if nAt != 0
      ADel( ::oMenu:aItems, nAt )
      ASize( ::oMenu:aItems, Len( ::oMenu:aItems ) - 1 )
   endif

   nResult = RemoveMenu( ::oMenu:hMenu, ::nId, MF_BYCOMMAND )
   
   if ! Empty( ::hBitmap )
      DeleteObject( ::hBitmap )
   endif
   
return nResult
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 90
Joined: Wed Nov 07, 2007 08:56 AM
Re: Creazione menu a runtime
Posted: Wed May 21, 2014 04:57 PM

Antonio, many thanks: with your change it works very well. :D

Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: Creazione menu a runtime
Posted: Fri Jun 06, 2014 06:58 PM

scusa patrizio
mi dici per favore ( magari con un test sample) che cosa fa la modifica perchè non l'ho capita ....grazie

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com

Continue the discussion