CURVAL( ) Function

Returns field values directly from disk for a table or a remote data source.

CURVAL(cExpression [, cTableAlias | nWorkArea])

Return Values

Character, Currency, Date, DateTime, Double, Float, Logical, Numeric, or Memo

Parameters

  • cExpression
    Specifies an expression whose value CURVAL( ) 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.
  • cTableAlias
    Specifies the alias of the table from which the field values are returned from disk for a table or a remote data source.
  • nWorkArea
    Specifies the work area of the table from which the field values are returned from disk for a table or a remote data source.

Remarks

The field values returned by CURVAL( ) and OLDVAL( ) can be compared to determine if another user on a network changed the field values while the fields were being edited. CURVAL( ) and OLDVAL( ) can only return different values when optimistic row or table buffering is enabled. Optimistic row or table buffering is enabled with CURSORSETPROP( ).

Note   If you are working with a view in a multiuser environment, the values returned by CURVAL( ) might not be up to date unless you call the REFRESH( ) function first. Data returned by a view is buffered, and the CURVAL( ) function reads values from the buffer. However, if other users have changed data in the underlying tables for the view, the buffered data is not updated until the REFRESH( ) function is called.

CURVAL( ) returns field values for the current record, and the return value data type is determined by the expression you specify with cExpression.

The value is returned for the table or cursor open in the currently selected work area if CURVAL( ) is issued without the optional cTableAlias or nWorkArea arguments.

Example

This example creates a free table named mytable, and a value of "One" is inserted into the cDigit field. Optimistic table buffering is enabled with SET MULTILOCKS ON and CURSORSETPROP( ).

A value of "Two" is then inserted into the cDigit field, and CURVAL( ) and OLDVAL( ) are used to display the original cDigit values. TABLEUPDATE( ) is used to commit the changes to the table, and CURVAL( ) and OLDVAL( ) are used to display the new cDigit values. Note that because this is a single user example, CURVAL( ) and OLDVAL( ) return the identical values.

CLOSE DATABASES
CLEAR

CREATE TABLE mytable FREE (cDigit C(10)) 
* Store original value
INSERT INTO mytable (cDigit) VALUES ("One")
SET MULTILOCKS ON        && Allow optimistic table buffering
= CURSORSETPROP("Buffering",5)   && Optimistic table buffering on
REPLACE cDigit WITH "Two"    && New value

? "Current value: " + CURVAL("cDigit", "mytable")
? "Old value: " + OLDVAL("cDigit", "mytable")
= TABLEUPDATE(.T.)       && Commit changes made to table
? "Table changes committed"
? "New current value: " + CURVAL("cDigit", "mytable")
? "New old value: " + OLDVAL("cDigit", "mytable")

See Also

GETFLDSTATE( ) | OLDVAL( ) | TABLEREVERT( ) | TABLEUPDATE( ) | CURSORSETPROP( )