Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- RLIB 3.0a Reference - <b>function:</b> memorize() http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Function:    MEMORIZE()

Purpose:     Save field values from a database record to memory variables.

Syntax:      MEMORIZE( [ blank ] )

Arguments:   blank       - Optional logical value which if specified as
                           True tells MEMORIZE() to create an empty
                           M->memvar of the associated field type for each
                           database field.

Returns:     True if all fields successively stored to memory variables.

Description: This function is designed to be used in conjunction with the
             CHANGED(), MREPLACE(), and FORGET() functions; they are all a
             team.  Put together, they simplify the scattering and
             gathering of database field contents into and from associated
             memory variables (some languages call them temporary field
             variables).  What MEMORIZE() does is to create a PUBLIC
             memory variable with the same name as each of the fields in
             the current record of the currently selected database file,
             and assign to that memory variable the value of its
             associated field.  You then GET the contents of the memory
             variable rather than GETting the field directly.  After your
             READ is finished, you check to see if any of the memory
             variable values have CHANGED() from their database field
             counterparts and, if so, issue a MREPLACE() then FORGET()
             them.  The process may seem a little complicated at first,
             but it's a lot easier than cluttering up code with STORE TO's
             and REPLACE WITH's.

Notes:       Used to store a working copy of all the database record field
             contents to memory variables for editing.  This is good
             programming practice in that you should never GET a field
             directly, but only work with a copy which can later be
             REPLACEd.  The <blank> option is useful for creating a set of
             field variables when appending a new record.  Remember,
             memory variables created with MEMORIZE() have the same name
             as their database field counterparts.  Whenever there are
             fields and memory variables with the same names, fields take
             precedence.  So to access these variables you must preface
             the variable name with the memory variable identifier alias
             M->.

             Each memory variable created is the same data type as its
             associated field.  If the optional blank parameter is
             supplied, each of these variables are empty (Memo field
             variables are initialized as a character string of zero
             length).  The following table of samples gives the data types
             created:

             FIELD NAME  FIELD TYPE  LEN  VARIABLE NAME  BLANK VALUE
             Name        Character    32  M->name        SPACE(32)
             BirthDate   Date          8  M->birthdate   CTOD(" ")
             Age         Numeric       2  M->age         0
             Male        Logical       1  M->male        .F.
             Comments    Memo         10  M->comments    ""

Example:     *-- store empty field values for a new record
             MEMORIZE(.T.)

             *-- get the data
             @ 1,0 SAY "Enter full name" GET M->name
             @ 2,0 SAY "Enter birthdate" GET M->birthdate
             @ 3,0 SAY "Enter age      " GET M->age  PICTURE "##"
             *-- remember to always PICTURE numeric memory variables
             READ

             *-- now add the new record and put in the data
             IF NO_APPEND()
                *-- error message
                RETURN
             ENDIF
             MREPLACE()

             *-- now release the public variables
             FORGET()

Source:      RL_MEMOR.PRG

See also:    CHANGED(), MREPLACE(), FORGET()

See Also: CHANGED() MREPLACE() FORGET()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson