Function GetReader() Foundation

Implements the standard READ behavior of a single Get object for the key codes returned by the function Inkey().

GetReader( <oGet> ) --> NIL
<oGet> is the Get object used for data input.

The return value of GetReader() is always NIL.


GetReader() implements the standard READ behavior of individual Get objects and reads the keyboard with the function Inkey(). The keyboard codes of Inkey() are handled by the function GetApplyKey(). GetReader() also takes care of data validation before and after data input.

GetReader() is a compatibility function which exists to facilitate porting Clipper programs to Xbase++. In order to simplify porting, GetReader() is the default function with which keyboard entry is handled by the Get system. In native Xbase++ programming, AppEvent() should be used to read events instead of Inkey(). Switching between reading the keyboard using Inkey() and reading events using AppEvent() can be done by calling GetEnableEvents(.T.|.F.).

User-defined Get readers can be used to replace the default reader of the Xbase++ Get system by specifying a function call in the form of a code block, which replaces GetEventReader() as the input handler. This code block is assigned to the instance variable oGet:reader. When the instance variable contains a code block, the block is executed and the referenced function gets passed the Get object instead of GetEventReader().

Get reader user-defined function

// The example implements a user-defined Get reader 
// when using AppEvent() instead of Inkey(). No special 
// character input with READ is allowed. German umlauts 
// and the " " are translated to two characters in the reader 
// NoUmlauts(). All other keys or characters are handled by 
// the default mechanism GetApplyKey(). 

#include "" 

   LOCAL cName1 := Space(20),  cName2 := Space(20) 

   @  8,10 SAY "Input without umlauts and  " 

   @ 10,10 SAY "First name:" GET cName1 ;  // Defines Get reader 
                          SEND reader := {|o| NoUmlauts(o) } 
   @ 12,10 SAY " Last name:" GET cName2 ; 
                          SEND reader := {|o| NoUmlauts(o) } 


PROCEDURE NoUmlauts( oGet ) 
   LOCAL bBlock, cChar, nKey 

   IF GetPreValidate( oGet )        // Completes prevalidation 
      oGet:setFocus()               // Sets input focus to Get 

      bBlock := {|o,n1,n2| ;        // Translates to two characters 
         GetApplyKey(o,n1),;        // in the code block 
         IIf( o:typeOut, NIL, GetApplyKey(o,n2) ) } 

      DO WHILE oGet:exitState == GE_NOEXIT 

         IF oGet:typeOut               // No editable characters 
            oGet:exitState := GE_ENTER // to the right of the cursor 
                                       // Reads events 
         DO WHILE oGet:exitState == GE_NOEXIT 
            nKey := Inkey(0) 
            cChar:= Chr(nKey) 

            DO CASE                    // Translates special 
                                       // characters 
            CASE cChar == " " 
               Eval( bBlock, oGet, Asc("A"), Asc("e") ) 
            CASE cChar == " " 
               Eval( bBlock, oGet, Asc("O"), Asc("e") ) 
            CASE cChar == " " 
               Eval( bBlock, oGet, Asc("U"), Asc("e") ) 
            CASE cChar == " " 
               Eval( bBlock, oGet, Asc("a"), Asc("e") ) 
            CASE cChar == " " 
               Eval( bBlock, oGet, Asc("o"), Asc("e") ) 
            CASE cChar == " " 
               Eval( bBlock, oGet, Asc("u"), Asc("e") ) 
            CASE cChar == " " 
               Eval( bBlock, oGet, Asc("s"), Asc("s") ) 
               GetApplyKey( oGet, nKey ) 


         IF ! GetPostValidate( oGet ) 
            oGet:exitState:= GE_NOEXIT    // Postvalidation 
         ENDIF                            // has failed 

      oGet:killFocus()                    // Sets back input focus 



If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.