Life time of a MDI CHILD

Life time of a MDI CHILD

Postby mauri.menabue » Sun Aug 30, 2020 8:25 am

Hi all,
try this minimal example, why after end of MDICHILD oChild the window is already
active ?

Code: Select all  Expand view  RUN


#include "fivewin.ch"

function Main()

   local oWnd, oFont
   local aData := { 1, 2, 3, 'Something' }
   local nVar := 99, cVar := 'Hello'
   local oMenu

   DEFINE FONT oFont NAME 'TAHOMA' SIZE 0,-15
 
   MENU oMenu
      MENUITEM "Child" ACTION Child( oWnd )
      MENUITEM "Quit"  ACTION oWnd:End()
   ENDMENU
 
   DEFINE WINDOW oWnd MDI MENU oMenu
   oWnd:SetFont( oFont )
   oWnd:bRClicked := { || Debug( "oWnd", oWnd ) }

   ACTIVATE WINDOW oWnd

   RELEASE FONT oFont

return nil


function child( oParent )

   local oChild
   local oFont
   local aData := { 1, 2, 3, 'Something from child' }
   local nVar := 99, cVar := 'Hello from child'
   local lExit := .F.
   local oLbl01

   DEFINE FONT oFont NAME 'TAHOMA' SIZE 0,-15
   DEFINE WINDOW oChild MDICHILD OF oParent
   oChild:SetFont( oFont )
   oChild:bRClicked := { || Debug( "oChild", oChild ) }
   
   @ 10 , 10 SAY oLbl01 VAR "Codice" OF oChild

   ACTIVATE WINDOW oChild VALID ( lExit := .T. ,  .T. )

   STOPUNTIL( { || lExit } )

   Debug( "oChild", oChild )
   RELEASE FONT  oFont

return nil

init procedure Inizio
return  
 
exit procedure Fine
return  


*--------------------------------------------------------------------------------  
Function Debug( cVar01, uVar01 )
*--------------------------------------------------------------------------------  

    LOCAL aStack := {}
    LOCAL nStack := 1  

    DEFAULT cVar01 := ""
    DEFAULT uVar01 := NIL

      DO WHILE .NOT. Empty( ProcName(nStack) )
         AAdd( aStack, { ProcLine(nStack), ProcFile(nStack), ProcName(nStack) } )
         nStack ++
      ENDDO

    Xbrowse( aStack, "Stack ",, { |o| o:cHeaders := { "Linea", "File", "Procedura" } } )
   
    XBrowse( ArrTranspose( { { cVar01 } , Eval( { || { uVar01 } } ) } ), ;
            ProcName(0) + " : Linea : " + LTrim( Str( ProcLine(0) ) ),, ;
            { |o| o:cHeaders := { "Variabile", "Valore" } } )
RETURN NIL

 



TIA
User avatar
mauri.menabue
 
Posts: 155
Joined: Thu Apr 17, 2008 2:38 pm

Re: Life time of a MDI CHILD

Postby karinha » Sun Aug 30, 2020 2:31 pm

Hello, I didn't find any errors.

Code: Select all  Expand view  RUN

#include "fivewin.ch"

STATIC oWnd

function Main()

   local oFont
   local aData := { 1, 2, 3, 'Something' }
   local nVar := 99, cVar := 'Hello'
   local oMenu

   DEFINE FONT oFont NAME 'TAHOMA' SIZE 0,-15
 
   MENU oMenu
      MENUITEM "Child" ACTION( Child( oWnd ) )
      MENUITEM "Quit"  ACTION( oWnd:End() )
   ENDMENU
 
   DEFINE WINDOW oWnd MDI MENU oMenu

   oWnd:SetFont( oFont )
   oWnd:bRClicked := { || Debug( "oWnd", oWnd ) }

   ACTIVATE WINDOW oWnd CENTER

   RELEASE FONT oFont

return nil


function child( oParent )

   local oChild
   local oFont
   local aData := { 1, 2, 3, 'Something from child' }
   local nVar := 99, cVar := 'Hello from child'
   local lExit := .F.
   local oLbl01

   DEFINE FONT oFont NAME 'TAHOMA' SIZE 0,-15

   DEFINE WINDOW oChild MDICHILD OF oParent

   oChild:SetFont( oFont )
   oChild:bRClicked := { || Debug( "oChild", oChild ) }
   
   @ 10 , 10 SAY oLbl01 VAR "Codice" OF oChild

   ACTIVATE WINDOW oChild VALID ( lExit := .T. ,  .T. )

   STOPUNTIL( { || lExit } )

   Debug( "oChild", oChild )

   RELEASE FONT  oFont

return nil

init procedure Inizio
return
 
exit procedure Fine
return


*--------------------------------------------------------------------------------  
Function Debug( cVar01, uVar01 )
*--------------------------------------------------------------------------------  

    LOCAL aStack := {}
    LOCAL nStack := 1  

    DEFAULT cVar01 := ""
    DEFAULT uVar01 := NIL

    WHILE .NOT. Empty( ProcName(nStack) )

       SYSREFRESH()

       AAdd( aStack, { ProcLine(nStack), ProcFile(nStack), ProcName(nStack) } )

       nStack ++

    ENDDO

    Xbrowse( aStack, "Stack ",, { |o| o:cHeaders := { "Linea", "File", "Procedura" } } )
   
    XBrowse( ArrTranspose( { { cVar01 } , Eval( { || { uVar01 } } ) } ), ;
             ProcName(0) + " : Linea : " + LTrim( Str( ProcLine(0) ) ),, ;
             { |o| o:cHeaders := { "Variabile", "Valore" } } )

RETURN NIL
 


Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7842
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Life time of a MDI CHILD

Postby mauri.menabue » Sun Aug 30, 2020 2:41 pm

Hello Karinha,
no mistake, I wonder why the 'oChild' variable is still defined after it's closed
thank
User avatar
mauri.menabue
 
Posts: 155
Joined: Thu Apr 17, 2008 2:38 pm

Re: Life time of a MDI CHILD

Postby Enrico Maria Giordano » Mon Aug 31, 2020 8:48 am

Because oChild is a LOCAL variable. It is destroyed after the end of the function where it is defined.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8718
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Life time of a MDI CHILD

Postby mauri.menabue » Tue Sep 01, 2020 6:56 am

Hi Enrico,
you're right !
thanks
User avatar
mauri.menabue
 
Posts: 155
Joined: Thu Apr 17, 2008 2:38 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 53 guests