Life time of a MDI CHILD

Post Reply
User avatar
mauri.menabue
Posts: 89
Joined: Thu Apr 17, 2008 2:38 pm

Life time of a MDI CHILD

Post by mauri.menabue »

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

Code: Select all


#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
karinha
Posts: 4882
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Life time of a MDI CHILD

Post by karinha »

Hello, I didn't find any errors.

Code: Select all

#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
User avatar
mauri.menabue
Posts: 89
Joined: Thu Apr 17, 2008 2:38 pm

Re: Life time of a MDI CHILD

Post by mauri.menabue »

Hello Karinha,
no mistake, I wonder why the 'oChild' variable is still defined after it's closed
thank
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: Life time of a MDI CHILD

Post by Enrico Maria Giordano »

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

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

Re: Life time of a MDI CHILD

Post by mauri.menabue »

Hi Enrico,
you're right !
thanks
Post Reply