How to implement GETACTIVE()?

User avatar
Enrico Maria Giordano
Posts: 8783
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 8 times
Contact:

How to implement GETACTIVE()?

Post 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 | Expand

#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
User avatar
cnavarro
Posts: 6656
Joined: Wed Feb 15, 2012 8:25 pm
Location: España
Has thanked: 8 times
Been thanked: 10 times

Re: How to implement GETACTIVE()?

Post by cnavarro »

Something like that?

Code: Select all | Expand



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

 
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
Enrico Maria Giordano
Posts: 8783
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 8 times
Contact:

Re: How to implement GETACTIVE()?

Post 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 | Expand

#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
User avatar
cnavarro
Posts: 6656
Joined: Wed Feb 15, 2012 8:25 pm
Location: España
Has thanked: 8 times
Been thanked: 10 times

Re: How to implement GETACTIVE()?

Post by cnavarro »

Try

Code: Select all | Expand



    FOR i = 1 TO LEN( oDlg:aControls )
        IF oDlg:aControls[ i ]:HasFocus()
            RETURN oDlg:aControls[ i - if( i = 1, 0, 1 ) ]
        ENDIF
    NEXT
 
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
Enrico Maria Giordano
Posts: 8783
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 8 times
Contact:

Re: How to implement GETACTIVE()?

Post 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
User avatar
cnavarro
Posts: 6656
Joined: Wed Feb 15, 2012 8:25 pm
Location: España
Has thanked: 8 times
Been thanked: 10 times

Re: How to implement GETACTIVE()?

Post 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.
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
Enrico Maria Giordano
Posts: 8783
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 8 times
Contact:

Re: How to implement GETACTIVE()?

Post by Enrico Maria Giordano »

No, it is not. Try this sample. Neither of the two functions will work:

Code: Select all | Expand

#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
User avatar
cnavarro
Posts: 6656
Joined: Wed Feb 15, 2012 8:25 pm
Location: España
Has thanked: 8 times
Been thanked: 10 times

Re: How to implement GETACTIVE()?

Post by cnavarro »

Your example works fine.
What is it that I don't understand about your problem?
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
Enrico Maria Giordano
Posts: 8783
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 8 times
Contact:

Re: How to implement GETACTIVE()?

Post 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.
User avatar
cnavarro
Posts: 6656
Joined: Wed Feb 15, 2012 8:25 pm
Location: España
Has thanked: 8 times
Been thanked: 10 times

Re: How to implement GETACTIVE()?

Post 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
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
MaxP
Posts: 91
Joined: Thu Jul 12, 2007 2:02 pm
Has thanked: 1 time
Contact:

Re: How to implement GETACTIVE()?

Post by MaxP »

Ciao Enrico,

try this

Code: Select all | Expand

#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
User avatar
Enrico Maria Giordano
Posts: 8783
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 8 times
Contact:

Re: How to implement GETACTIVE()?

Post 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
User avatar
Enrico Maria Giordano
Posts: 8783
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 8 times
Contact:

Re: How to implement GETACTIVE()?

Post 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
User avatar
cnavarro
Posts: 6656
Joined: Wed Feb 15, 2012 8:25 pm
Location: España
Has thanked: 8 times
Been thanked: 10 times

Re: How to implement GETACTIVE()?

Post 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
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
Enrico Maria Giordano
Posts: 8783
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 8 times
Contact:

Re: How to implement GETACTIVE()?

Post by Enrico Maria Giordano »

You are not trying my last code. Try it, please. It is not working.

EMG
Post Reply