Page 1 of 3

How to implement GETACTIVE()?

Posted: Tue Oct 27, 2020 10:50 am
by Enrico Maria Giordano
I need to implemente a generic GETACTIVE() function (just like the old Clipper one). Any suggestion? This is a sample of what I need:

Code: Select all

#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL oDlg

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

    DEFINE DIALOG oDlg

    @ 1, 1 GET cVr1 VALID !EMPTY( GETACTIVE():VarGet() )  // !EMPTY( cVr1 )
    @ 3, 1 GET cVr2

    ACTIVATE DIALOG oDlg;
             CENTER

    RETURN NIL
EMG

Re: How to implement GETACTIVE()?

Posted: Tue Oct 27, 2020 12:38 pm
by cnavarro
Something like that?

Code: Select all


Function GetActive( oDlg )

   local oObj
   local x
   For x = 1 to Len( oDlg:aControls )
      if oDlg:aControls[ x ]:HasFocus()
         oObj  := oDlg:aControls[ x ]
         Exit
      endif
   Next x
/*
   AEVal( oDlg:aControls, { | o | if( o:HasFocus(), oObj := o, ) } )
*/
/*
   hb_ForNext( 1, Len( oDlg:aControls ), { | i | if( oDlg:aControls[ i ]:HasFocus(), oObj := oDlg:aControls[ i ],  ) }, 1 )
*/

Return oObj

 

Re: How to implement GETACTIVE()?

Posted: Tue Oct 27, 2020 1:40 pm
by Enrico Maria Giordano
Thank you. Unfortunately, it doesn't work as the focused GET is the next, not the current. Try this sample:

Code: Select all

#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL oDlg

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

    DEFINE DIALOG oDlg

    @ 1, 1 GET cVr1 VALID !EMPTY( GETACTIVE( oDlg ):VarGet() )
    @ 3, 1 GET cVr2

    ACTIVATE DIALOG oDlg;
             CENTER

    RETURN NIL


FUNCTION GETACTIVE( oDlg )

    LOCAL i

    FOR i = 1 TO LEN( oDlg:aControls )
        IF oDlg:aControls[ i ]:HasFocus()
            RETURN oDlg:aControls[ i ]
        ENDIF
    NEXT

    RETURN NIL
EMG

Re: How to implement GETACTIVE()?

Posted: Tue Oct 27, 2020 1:58 pm
by cnavarro
Try

Code: Select all


    FOR i = 1 TO LEN( oDlg:aControls )
        IF oDlg:aControls[ i ]:HasFocus()
            RETURN oDlg:aControls[ i - if( i = 1, 0, 1 ) ]
        ENDIF
    NEXT
 

Re: How to implement GETACTIVE()?

Posted: Tue Oct 27, 2020 2:08 pm
by Enrico Maria Giordano
No, it cannot work, sorry. First, because it is a generic function, not necessarily used inside VALID. And second, because the previous control doesn't have to be a GET but any controls.

EMG

Re: How to implement GETACTIVE()?

Posted: Tue Oct 27, 2020 2:13 pm
by cnavarro
This, obviously, is for the VALID clause of your example, in any other case, with HasFocus () is enough, as in my first example.

Re: How to implement GETACTIVE()?

Posted: Tue Oct 27, 2020 2:20 pm
by Enrico Maria Giordano
No, it is not. Try this sample. Neither of the two functions will work:

Code: Select all

#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL oDlg

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

    DEFINE DIALOG oDlg

    @ 1, 1 SAY "Test 1:" GET cVr1 VALID !EMPTY( GETACTIVE( oDlg ):VarGet() )
    @ 3, 1 SAY "Test 2:" GET cVr2

    ACTIVATE DIALOG oDlg;
             CENTER

    RETURN NIL


FUNCTION GETACTIVE( oDlg )

    LOCAL i

    FOR i = 1 TO LEN( oDlg:aControls )
        IF oDlg:aControls[ i ]:HasFocus()
            RETURN oDlg:aControls[ i - IF( i = 1, 0, 1 ) ]
        ENDIF
    NEXT

    RETURN NIL
EMG

Re: How to implement GETACTIVE()?

Posted: Tue Oct 27, 2020 2:36 pm
by cnavarro
Your example works fine.
What is it that I don't understand about your problem?

Re: How to implement GETACTIVE()?

Posted: Tue Oct 27, 2020 2:43 pm
by Enrico Maria Giordano
No, it doesn't work. You can move the focus from the first GET even if it is empty. Please note the VALID clause.

Re: How to implement GETACTIVE()?

Posted: Tue Oct 27, 2020 2:54 pm
by cnavarro
Enrico Maria Giordano wrote:No, it doesn't work. You can move the focus from the first GET even if it is empty. Please note the VALID clause.
Enrico, I know this, and your sample run OK
Valid clause not allow move to second GET if GetVar() is empty

If you use xHarbour, you may have to use (GetActive (oDlg): oGet: VarGet ()) in case of GETs controls

Re: How to implement GETACTIVE()?

Posted: Tue Oct 27, 2020 2:56 pm
by MaxP
Ciao Enrico,

try this

Code: Select all

#include "Fivewin.ch"


FUNCTION MAIN()
        LOCAL oDlg
        LOCAL cVr1 := "FIRST" + SPACE( 15 )
        LOCAL cVr2 := "SECOND" + SPACE( 14 )
        
        SET KEY VK_F2 TO MYGET()
        
        DEFINE DIALOG oDlg TITLE "TEST"
        
        // @ 1, 1 GET cVr1 VALID !EMPTY( MYGETACTIVE():GetText() )  // !EMPTY( cVr1 )
        @ 1, 1 GET cVr1
        @ 3, 1 GET cVr2
        
        ACTIVATE DIALOG oDlg CENTER
RETURN NIL

STATIC FUNCTION MYGETACTIVE()
        LOCAL   oGet
        
        oGet := oWndFromhWnd( GetFocus() )
        IF oGet <> NIL
                IF oGet:ClassName() <> "TGET"
                        oGet := NIL
                ENDIF                
        ENDIF
RETURN oGet

STATIC FUNCTION MYGET()
        LOCAL   cBuf, oGet

        oGet := MYGETACTIVE()
        IF oGet <> NIL
            cBuf := oGet:GetText()
            MsgStop( cBuf )
        ENDIF
RETURN NIL
The problem is that when you use the function on valid the focus is already on the next field

Massimo

Re: How to implement GETACTIVE()?

Posted: Tue Oct 27, 2020 3:07 pm
by Enrico Maria Giordano
cnavarro wrote:
Enrico Maria Giordano wrote:No, it doesn't work. You can move the focus from the first GET even if it is empty. Please note the VALID clause.
Enrico, I know this, and your sample run OK
Valid clause not allow move to second GET if GetVar() is empty

If you use xHarbour, you may have to use (GetActive (oDlg): oGet: VarGet ()) in case of GETs controls
No, it doesn't work either, sorry.

EMG

Re: How to implement GETACTIVE()?

Posted: Tue Oct 27, 2020 3:08 pm
by Enrico Maria Giordano
MaxP wrote:The problem is that when you use the function on valid the focus is already on the next field
Yes, I know. Any solutions?

EMG

Re: How to implement GETACTIVE()?

Posted: Tue Oct 27, 2020 3:27 pm
by cnavarro
Enrico Maria Giordano wrote:
cnavarro wrote:
Enrico Maria Giordano wrote:No, it doesn't work. You can move the focus from the first GET even if it is empty. Please note the VALID clause.
Enrico, I know this, and your sample run OK
Valid clause not allow move to second GET if GetVar() is empty

If you use xHarbour, you may have to use (GetActive (oDlg): oGet: VarGet ()) in case of GETs controls
No, it doesn't work either, sorry.

EMG
Yes, yes, run OK, loo
Image

Re: How to implement GETACTIVE()?

Posted: Tue Oct 27, 2020 3:34 pm
by Enrico Maria Giordano
You are not trying my last code. Try it, please. It is not working.

EMG