PRB: GET VALID Routine Is Not Called When Switching Windows

ID: Q99609

2.50 2.00 2.50a | 2.50 2.50a

MS-DOS          | WINDOWS
kbprg kbprb

The information in this article applies to:

SYMPTOMS

The GET VALID routine in a program is not called when the user switches between windows either by pressing CTRL+F1 or by choosing Next Window from the window's Control-menu box. To demonstrate this behavior, run the following program:

   DEFINE WINDOW test1 FROM 2,2 TO 10,20 ;
     FLOAT ;
     GROW ;
     CLOSE ;
     SYSTEM ;
     TITLE "TEST1"
   ACTIVATE WINDOW TEST1
   @ 2,2 GET x DEFAULT "Hello!" VALID hello()

   DEFINE WINDOW test2 FROM 12,2 TO 20,20 ;
     FLOAT ;
     GROW ;
     CLOSE ;
     SYSTEM ;
     TITLE "TEST2"
   ACTIVATE WINDOW TEST2
   @ 2,2 GET y DEFAULT "Goodbye!" VALID hello()

   READ CYCLE
   CLEAR ALL

   PROCEDURE hello
     WAIT WINDOW WLAST()

CAUSE

This is the expected behavior for FoxPro.

RESOLUTION

To force the VALID routine to execute, place it in the READ DEACTIVATE clause. The following steps demonstrate how to do this through the FoxPro Screen Builder.

1. Add the following to the Setup code:

      PUBLIC hasvalid  && Memory variable used to determine if field
                       && has associated VALID clause.
      hasvalid = .F.

2. In the WHEN snippet for each GET field, add one of the following lines
   as appropriate:

      hasvalid = .T.   && If the GET field has a VALID routine.
      hasvalid = .F.   && If the GET field does not have a VALID
                       && routine.

3. In the VALID snippet for each GET field that has a VALID routine, add
   the following line as a procedure:

      DO (varread())   && Causes the procedure that is named the same
                       && as the current GET field to execute.

4. Define all VALID procedures in the cleanup code. The name of each
   procedure should be the name of the associated GET field.

5. Add the following code to the READ DEACTIVATE clause:

      IF hasvalid
         DO (varread()) && Named expression to cause proper procedure
                        && to execute. Preferred to macro
                        && substitution.
      ENDIF
      RETURN .F.        && Necessary to keep the READ from
                        && terminating.

The GET VALID routine is also called when the user switches between windows by clicking on another window.

Additional reference words: FoxDos FoxWin 2.00 2.50 2.50a KBCategory: kbprg kbprb KBSubcategory: FxprgMacrosub

Keywords          : FxprgMacrosub 
Version           : 2.50 2.00 2.50a | 2.50 2.50a
Platform          : MS-DOS WINDOWS

Last Reviewed: April 30, 1996