home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / clipper / snip0693.zip / REQUIRE.PRG < prev    next >
Text File  |  1992-09-06  |  3KB  |  65 lines

  1. When processing multiple gets with a single read, it is possible (and likely)
  2. that the user might terminate the read before entering a get whose data is
  3. required.  I've often wished, if the user terminated the read for any other
  4. reason than aborting it, that the gets could be re-validated in a painless
  5. manner to ensure that all *required* fields were entered.  Not wanting to resort
  6. to a separate validation routine to be called after the read terminates, I poked
  7. around 5.01's GETSYS.prg and came up with the following solution.
  8.  
  9. I use the "cargo" instance variable to hold a logical value indicating whether
  10. the get is required, as follows:
  11.  
  12.   #define REQUIRED  .t.
  13.  
  14.   @ 5, 10 get cTest1 pict 'XXXXX' valid { |oGet| GottaHavIt( oGet ) }
  15.   atail( GetList ):cargo := REQUIRED
  16.  
  17.   @ 6, 10 get cTest2 pict 'XXXXX' valid CheckTest2( cTest2 )
  18.   atail( GetList ):cargo := REQUIRED
  19.  
  20. That's all the programming necessary in your day to day coding.  The rest is a
  21. one-time modification to GETSYS.prg as shown below.  You could redefine the
  22. @..GET command with a "REQUIRED" clause to make it even simpler.  If you're
  23. already using cargo for some other purpose, you can make it a nested array and
  24. stick the REQUIRED flag in the array wherever it suits your fancy (and modify
  25. the code below accordingly):
  26.  
  27. Insert these two lines immediately after the line
  28. "local savedGetSysVars" in the ReadModal() function:
  29.  
  30.   local nGets := len( GetList )
  31.   local n
  32.  
  33. Insert this code fragment immediately after the line
  34. "pos := Settle( GetList, pos )" and before the line "end" in the ReadModal()
  35. function:
  36.  
  37.   // validate gets whose cargo value is .t. (required)
  38.   if pos = 0 .and. LastExit != GE_ESCAPE
  39.     for n := 1 to nGets
  40.       get := GetList[ n ]
  41.       if get:cargo != nil .and. get:cargo   // Is the get required?
  42.         if get:postBlock != nil             // Is there a valid?
  43.           if ( GetPreValidate( get ) )      // If when satisfied...
  44.             get:setFocus()                  // Give the get focus
  45.             if ( !GetPostValidate( get ) )  //  and validate it.
  46.               pos := n
  47.               exit
  48.             endif
  49.             get:KillFocus()
  50.           endif
  51.         endif
  52.       endif
  53.     next
  54.   endif
  55.  
  56. Insert this line immediately after the line
  57. "if ( exitState == GE_ESCAPE .or.  exitState == GE_WRITE )" and
  58. before the line "return ( 0 )" in the Settle() function:
  59.  
  60.   LastExit := exitState
  61.  
  62. That should be all there is to it.  I've made other mods to GetSys,
  63. but I think I pulled out the ones pertinent to the topic.  Please
  64. give me some feedback if you try this.
  65.