GETFLDSTATE( ) Function

Returns a numeric value indicating if a field in a table or cursor has been edited or had a record appended, or if the deleted status of the current record has been changed.

GETFLDSTATE(cFieldName | nFieldNumber [, cTableAlias | nWorkArea])

Return Values

Numeric, Character, or .NULL.

Parameters

  • cFieldName | nFieldNumber
    Specifies the name of the field or the number of the field for which the edit status is returned. The field number nFieldNumber corresponds to the position of the field in the table or cursor structure. DISPLAY STRUCTURE or FIELD( ) can be used to determine a field's number.

    You can specify –1 for nFieldNumber to return a character string consisting of deletion and edit status values for all fields in the table or cursor. For example, if a table has five fields and only the first field has been edited, GETFLDSTATE( ) returns the following:

    121111
    

    The 1 in the first position indicates the deletion status has not been changed.

    You can also include 0 for nFieldNumber to determine if the deletion status of the current record has changed since the table or cursor was opened.

    Note   Using GETFLDSTATE( ) only determines if the deletion status of the current record has changed. For example, if you mark a record for deletion and then recall it, GETFLDSTATE( ) indicates the deletion status has changed even though the record's deletion status has returned to its original state. Use DELETED( ) to determine the current deletion status of a record.

  • cTableAlias
    Specifies the alias of the table or cursor for which the field edit or record deletion status is returned.

  • nWorkArea
    Specifies the work area of the table or cursor for which the field edit or record deletion status is returned.

    If you do not specify an alias or work area, GETFLDSTATE( ) returns a value for a field in the currently selected table or cursor.

Remarks

The following table lists the character return values and the corresponding edit or deletion status.

Return value Edit or deletion status
1 Field has not been edited or deletion status has not changed.
2 Field has been edited or deletion status has changed.
3 Field in an appended record has not been edited or deletion status has not changed for the appended record.
4 Field in an appended record has been edited or deletion status has changed for the appended record.
.NULL. At EOF( )

Row or table buffering must first be enabled with CURSORSETPROP( ) for GETFLDSTATE( ) to operate on local tables.

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

Example

The following example demonstrates how you can use GETFLDSTATE( ) to determine if the contents of a field have changed. MULTILOCKS is set to ON, a requirement for table buffering. The customer table in the testdata database is opened, and CURSORSETPROP( ) is then used to set the buffering mode to optimistic table buffering (5).

GETFLDSTATE( ) is issued to display a value (1) corresponding to the unmodified state of the cust_id field before it is modified. The cust_id field is modified with REPLACE, and GETFLDSTATE( ) is issued again to display a value (2) corresponding to the modified state of the cust_id field. TABLEREVERT( ) is used to return the table to its original state, and GETFLDSTATE( ) is issued again to display a value (1) corresponding to the original state of the cust_id field.

CLOSE DATABASES
CLEAR

SET MULTILOCKS ON         && Allow table buffering
OPEN DATABASE (HOME(2) + 'data\testdata')
USE Customer             && Open customer table
=CURSORSETPROP("Buffering",5,"customer")  && Enable table buffering

* Get field state on original cust_id field and display state
nState=GETFLDSTATE("cust_id")
DO DisplayState WITH nState

* Change field contents and display state
REPLACE cust_id    WITH "***"
nState=GETFLDSTATE("cust_id")
DO DisplayState WITH nState

* Discard table changes and display state
= TABLEREVERT(.T.)        && Discard all table changes
nState=GETFLDSTATE("cust_id")
DO DisplayState WITH nState

PROCEDURE DisplayState
PARAMETER nState
DO CASE
   CASE nState=1
      =MESSAGEBOX("Field has not been modified",0,"Results")
   OTHERWISE
      =MESSAGEBOX("Field has been modified",0,"Results")
ENDCASE

See Also

CURVAL( ) | DELETED( ) | FIELD( ) | OLDVAL( ) | CURSORSETPROP( ) | SETFLDSTATE( )