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> changed() http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Function:    CHANGED()

Purpose:     Test if memory copies of database fields have been changed.

Syntax:      CHANGED()

Arguments:   None

Returns:     True if any changes made to field variables since the last
             REPLACE, MREPLACE(), or MEMORIZE().

Description: CHANGED() is a database function designed to serve as a
             replacement for the Clipper UPDATED() function when used in
             conjunction with the MEMORIZE() function.  It may also be
             used to compare the contents of all fields in a record to
             previously MEMORIZED() copies to determine if changes have
             been made to the record since it was MEMORIZED().  CHANGED()
             tests to see if memory field variables have been changed from
             the associated field values after an edit.  This works better
             than Clipper's UPDATED() function because once you test for
             UPDATED(), the flag is cleared.  So if you go back and READ
             the data again, in a loop for instance, but do NOT change
             anything this second time around, UPDATED() will return .F.,
             even though something was changed previously.  Ideally, when
             testing for UPDATED() you want it to be .T. if any values
             have changed since the last REPLACE.

Notes:       CHANGED() is used in conjunction with the MEMORIZE(),
             MREPLACE(), and FORGET() functions.  These functions
             reference all of the fields in the current database and store
             the field values to memory variables of the same name,
             prefaced by M->.

Example:     *-- this way will not trap an update on a re-read
             DO WHILE .T.
                @ 1,0 GET M->name                && get data
                @ 2,0 GET M->city
                @ 3,0 GET M->state
                READ
                *-- if changed this will be true, however after going back
                *-- through the second time UPDATED() will only be true if
                *-- another change was made.  Pressing Escape the second
                *-- time will not be trapped as UPDATED() will be False.
                IF UPDATED()
                   IF LASTKEY() = 27             && escape key
                      IF BOXASK("W/R", "Abort edit? (y/N) ") != "Y"
                         LOOP
                      ENDIF
                   ENDIF
                ENDIF
                EXIT
             ENDDO

             *-- the following way will work correctly!

             *-- save all database field data to field variables
             MEMORIZE()
             DO WHILE .T.
                *-- get data (remember to preface memvars with M->)
                @ 1,0 GET M->name
                @ 2,0 GET M->city
                @ 3,0 GET M->state
                READ
                *-- CHANGED() will compare all M->memvars with the twin
                *-- field name to see if any values are different, and
                *-- will catch it no matter how many times thru the loop
                IF CHANGED()
                   IF LASTKEY() = 27             && escape key
                      IF BOXASK("W/R", "Abort edit? (y/N) ") != "Y"
                         LOOP
                      ENDIF
                   ENDIF
                ENDIF
                EXIT
             ENDDO

Source:      RL_CHANG.PRG

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

See Also: MEMORIZE() MREPLACE() FORGET()

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