Returns original field values for fields that have been modified but not updated.
OLDVAL(cExpression [, cTableAlias | nWorkArea])
- Specifies an expression whose original value OLDVAL(В ) returns from a table or a remote data source. cExpression is typically a field or an expression consisting of a set of fields from the table or remote data source.
- Specifies the alias of the table or cursor from which the original field values are returned.
- Specifies the work area of the table or cursor from which the original field values are returned.
Character, Currency, Date, DateTime, Double, Float, Integer, Logical, Numeric, or Memo
OLDVAL(В ) returns original field values for records in a Visual FoxPro table or cursor that has row or table buffering enabled with CURSORSETPROP(В ).
If a table in a database or a cursor has validation rules, OLDVAL(В ) does not require that row or table buffering be enabled in order to return original field values.
If the record pointer is moved to a different record when row buffering is enabled, or if TABLEUPDATE(В ) is issued to commit changes to the record, or there is some other action that causes an update, such as ending a transaction, the fields are updated and the original field values are no longer available.
The data type of the value OLDVAL(В ) returns is determined by the expression you specify with cExpression.
The original field values are returned for the table or cursor open in the currently selected work area if OLDVAL(В ) is issued without the optional cTableAlias or nWorkArea arguments.
The following example demonstrates how you can use OLDVAL(В ) to return original field value for a field in a buffered table. A table named
employees is created and INSERT вЂ“ SQL is used insert the value "Smith" into the
MULTILOCKS is set to ON, a requirement for table buffering. CURSORSETPROP(В ) is used to set the buffering mode to optimistic table buffering (5).
The original value of the
cLastName field (Smith) is displayed and then the
cLastName field is modified with REPLACE. The new value of the
cLastName field (Jones) is displayed. The original value of the
cLastName field (Smith) is displayed with OLDVAL(В ). TABLEUPDATE(В ) is then used to commit changes to the table. The updated value of the
cLastName field (Jones) is then displayed.
CLOSE DATABASES CLEAR * Create new table and add blank record CREATE TABLE employee (cLastName C(10)) APPEND BLANK * Insert initial value INSERT INTO employee (cLastName) VALUES ("Smith") * Enable and set table buffering SET MULTILOCKS ON && Allow table buffering =CURSORSETPROP("Buffering", 5, "employee" ) && Enable table buffering * Display initial value =MESSAGEBOX("Original cLastName value: "+ cLastName, 0, "Results") * Change record value and display results REPLACE cLastName WITH "Jones" =MESSAGEBOX("Modified cLastName value: "+ cLastName, 0, "Results") * Store the old value of the field to cTemp variable and display results cTemp=OLDVAL("cLastName", "employee") =MESSAGEBOX("Original cLastName value: "+ cTemp, 0, "Results") * Update table and display final value =TABLEUPDATE(.T.) =MESSAGEBOX("Final cLastName value: "+ cLastName, 0, "Results") * Close and delete example table file USE DELETE FILE employee.dbf