FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How to implement GETACTIVE()?
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
How to implement GETACTIVE()?
Posted: 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 (fw): Select all Collapse
#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
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: How to implement GETACTIVE()?
Posted: Tue Oct 27, 2020 12:38 PM
Something like that?

Code (fw): Select all Collapse
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
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: How to implement GETACTIVE()?
Posted: Tue Oct 27, 2020 01:40 PM
Thank you. Unfortunately, it doesn't work as the focused GET is the next, not the current. Try this sample:

Code (fw): Select all Collapse
#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
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: How to implement GETACTIVE()?
Posted: Tue Oct 27, 2020 01:58 PM
Try

Code (fw): Select all Collapse
聽 聽 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
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: How to implement GETACTIVE()?
Posted: Tue Oct 27, 2020 02: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

Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: How to implement GETACTIVE()?
Posted: Tue Oct 27, 2020 02: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
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: How to implement GETACTIVE()?
Posted: Tue Oct 27, 2020 02:20 PM
No, it is not. Try this sample. Neither of the two functions will work:

Code (fw): Select all Collapse
#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
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: How to implement GETACTIVE()?
Posted: Tue Oct 27, 2020 02: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
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: How to implement GETACTIVE()?
Posted: Tue Oct 27, 2020 02: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.

Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: How to implement GETACTIVE()?
Posted: Tue Oct 27, 2020 02: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
Posts: 99
Joined: Thu Jul 12, 2007 02:02 PM
Re: How to implement GETACTIVE()?
Posted: Tue Oct 27, 2020 02:56 PM
Ciao Enrico,

try this

Code (fw): Select all Collapse
#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
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: How to implement GETACTIVE()?
Posted: Tue Oct 27, 2020 03: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
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: How to implement GETACTIVE()?
Posted: Tue Oct 27, 2020 03: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
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: How to implement GETACTIVE()?
Posted: Tue Oct 27, 2020 03: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
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
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: How to implement GETACTIVE()?
Posted: Tue Oct 27, 2020 03:34 PM

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

EMG