Page 1 of 1

Life time of a MDI CHILD

Posted: Sun Aug 30, 2020 8:25 am
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

Re: Life time of a MDI CHILD

Posted: Sun Aug 30, 2020 2:31 pm
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.

Re: Life time of a MDI CHILD

Posted: Sun Aug 30, 2020 2:41 pm
by mauri.menabue
Hello Karinha,
no mistake, I wonder why the 'oChild' variable is still defined after it's closed
thank

Re: Life time of a MDI CHILD

Posted: Mon Aug 31, 2020 8:48 am
by Enrico Maria Giordano
Because oChild is a LOCAL variable. It is destroyed after the end of the function where it is defined.

EMG

Re: Life time of a MDI CHILD

Posted: Tue Sep 01, 2020 6:56 am
by mauri.menabue
Hi Enrico,
you're right !
thanks