How to implement GETACTIVE()?

How to implement GETACTIVE()?

Postby Enrico Maria Giordano » Tue Oct 27, 2020 10:50 am

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 view  RUN
#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
Enrico Maria Giordano
 
Posts: 8725
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: How to implement GETACTIVE()?

Postby cnavarro » Tue Oct 27, 2020 12:38 pm

Something like that?

Code: Select all  Expand view  RUN


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
cnavarro
 
Posts: 6552
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: How to implement GETACTIVE()?

Postby Enrico Maria Giordano » Tue Oct 27, 2020 1:40 pm

Thank you. Unfortunately, it doesn't work as the focused GET is the next, not the current. Try this sample:

Code: Select all  Expand view  RUN
#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
Enrico Maria Giordano
 
Posts: 8725
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: How to implement GETACTIVE()?

Postby cnavarro » Tue Oct 27, 2020 1:58 pm

Try

Code: Select all  Expand view  RUN


    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
cnavarro
 
Posts: 6552
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: How to implement GETACTIVE()?

Postby Enrico Maria Giordano » Tue Oct 27, 2020 2:08 pm

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
Enrico Maria Giordano
 
Posts: 8725
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: How to implement GETACTIVE()?

Postby cnavarro » Tue Oct 27, 2020 2:13 pm

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
cnavarro
 
Posts: 6552
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: How to implement GETACTIVE()?

Postby Enrico Maria Giordano » Tue Oct 27, 2020 2:20 pm

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

Code: Select all  Expand view  RUN
#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
Enrico Maria Giordano
 
Posts: 8725
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: How to implement GETACTIVE()?

Postby cnavarro » Tue Oct 27, 2020 2:36 pm

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
cnavarro
 
Posts: 6552
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: How to implement GETACTIVE()?

Postby Enrico Maria Giordano » Tue Oct 27, 2020 2:43 pm

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
Enrico Maria Giordano
 
Posts: 8725
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: How to implement GETACTIVE()?

Postby cnavarro » Tue Oct 27, 2020 2:54 pm

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
cnavarro
 
Posts: 6552
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: How to implement GETACTIVE()?

Postby MaxP » Tue Oct 27, 2020 2:56 pm

Ciao Enrico,

try this

Code: Select all  Expand view  RUN
#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
MaxP
 
Posts: 88
Joined: Thu Jul 12, 2007 2:02 pm

Re: How to implement GETACTIVE()?

Postby Enrico Maria Giordano » Tue Oct 27, 2020 3:07 pm

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: 8725
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: How to implement GETACTIVE()?

Postby Enrico Maria Giordano » Tue Oct 27, 2020 3:08 pm

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
Enrico Maria Giordano
 
Posts: 8725
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: How to implement GETACTIVE()?

Postby cnavarro » Tue Oct 27, 2020 3:27 pm

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
cnavarro
 
Posts: 6552
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: How to implement GETACTIVE()?

Postby Enrico Maria Giordano » Tue Oct 27, 2020 3:34 pm

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

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

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 13 guests