How to implement GETACTIVE()?

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

Re: How to implement GETACTIVE()?

Post by Enrico Maria Giordano »

This seems to work. Please test.

Code: Select all

#include "Fivewin.ch"


STATIC oGet


FUNCTION MAIN()

    LOCAL oDlg, oGt1, oGt2, oGt3

    LOCAL cVr1 := SPACE( 30 )
    LOCAL cVr2 := SPACE( 30 )
    LOCAL cVr3 := SPACE( 30 )

    LOCAL bVl1 := { || !Empty( GetActive():VarGet() ) }
    LOCAL bVl2 := { || !Empty( GetActive():VarGet() ) }
    LOCAL bVl3 := { || !Empty( GetActive():VarGet() ) }

    DEFINE DIALOG oDlg

    @ 1, 1 SAY "Test 1:" GET oGt1 VAR cVr1
    @ 2, 1 SAY "Test 2:" GET oGt2 VAR cVr2
    @ 3, 1 SAY "Test 3:" GET oGt3 VAR cVr3

    oGt1:bGotFocus = { || oGet := oGt1 }
    oGt2:bGotFocus = { || oGet := oGt2 }
    oGt3:bGotFocus = { || oGet := oGt3 }

    oGt1:bLostFocus = { || oGt1:bValid := { || .F. }, If( Eval( bVl1 ), oGt1:bValid := { || .T. }, ) }
    oGt2:bLostFocus = { || oGt2:bValid := { || .F. }, If( Eval( bVl2 ), oGt2:bValid := { || .T. }, ) }
    oGt3:bLostFocus = { || oGt3:bValid := { || .F. }, If( Eval( bVl3 ), oGt3:bValid := { || .T. }, ) }

    oGt1:bKeyDown = { | nKey | If( nKey = VK_F2, MsgInfo( GETACTIVE():VarGet() ), ) }
    oGt2:bKeyDown = { | nKey | If( nKey = VK_F2, MsgInfo( GETACTIVE():VarGet() ), ) }
    oGt3:bKeyDown = { | nKey | If( nKey = VK_F2, MsgInfo( GETACTIVE():VarGet() ), ) }

    ACTIVATE DIALOG oDlg;
             CENTER

    RETURN NIL


FUNCTION GETACTIVE()

    oGet:Assign()

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

Re: How to implement GETACTIVE()?

Post by Enrico Maria Giordano »

Improved version. What do you think?

Code: Select all

#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL oDlg, oGt1, oGt2, oGt3

    LOCAL cVr1 := SPACE( 30 )
    LOCAL cVr2 := SPACE( 30 )
    LOCAL cVr3 := SPACE( 30 )

    DEFINE DIALOG oDlg

    @ 1, 1 SAY "Test 1:" GET oGt1 VAR cVr1 VALID !EMPTY( GETACTIVE():VarGet() )
    @ 2, 1 SAY "Test 2:" GET oGt2 VAR cVr2 VALID !EMPTY( GETACTIVE():VarGet() )
    @ 3, 1 SAY "Test 3:" GET oGt3 VAR cVr3 VALID !EMPTY( GETACTIVE():VarGet() )

    oGt1:Cargo = oGt1:bValid
    oGt2:Cargo = oGt2:bValid
    oGt3:Cargo = oGt3:bValid

    oGt1:bGotFocus = { || GetActive( oGt1 ) }
    oGt2:bGotFocus = { || GetActive( oGt2 ) }
    oGt3:bGotFocus = { || GetActive( oGt3 ) }

    oGt1:bLostFocus = { || oGt1:bValid := { || .F. }, If( Eval( oGt1:Cargo ), oGt1:bValid := { || .T. }, ) }
    oGt2:bLostFocus = { || oGt2:bValid := { || .F. }, If( Eval( oGt2:Cargo ), oGt2:bValid := { || .T. }, ) }
    oGt3:bLostFocus = { || oGt3:bValid := { || .F. }, If( Eval( oGt2:Cargo ), oGt3:bValid := { || .T. }, ) }

    oGt1:bKeyDown = { | nKey | If( nKey = VK_F2, MsgInfo( GetActive():VarGet() ), ) }
    oGt2:bKeyDown = { | nKey | If( nKey = VK_F2, MsgInfo( GetActive():VarGet() ), ) }
    oGt3:bKeyDown = { | nKey | If( nKey = VK_F2, MsgInfo( GetActive():VarGet() ), ) }

    ACTIVATE DIALOG oDlg;
             CENTER

    RETURN NIL


FUNCTION GETACTIVE( oNew )

    STATIC oGet

    IF oNew != NIL
        oGet = oNew
    ENDIF

    oGet:Assign()

    RETURN oGet
EMG
Post Reply