SETFLDSTATE( ) Function
Assigns a field modification or deletion state value to a field or record in a table or cursor.
SETFLDSTATE(cFieldName | nFieldNumber, nFieldState [, cTableAlias
| nWorkArea])
Return Values
Logical
Parameters
cFieldName | nFieldNumber
Specifies the name or the number of the field for which the modification or deletion status is assigned. 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.To set the deletion status for the record, include 0 as the field number.
nFieldState
Specifies a value for the field modification or deletion status. The following table lists the field modification or deletion state value and the corresponding modification or deletion status:nFieldState Modification or deletion status 1 Field has not been modified or deletion status has not changed. 2 Field has been modified or deletion status has changed. 3 Field in an appended record has not been modified or deletion status has not changed for the appended record. 4 Field in an appended record has been modified or deletion status has changed for the appended record. cTableAlias
Specifies the alias of the table or cursor in which the modification or deletion status is assigned.nWorkArea
Specifies the work area of the table or cursor in which the modification or deletion status is assigned. The field modification or deletion state value is assigned for the table or cursor open in the currently selected work area if SETFLDSTATE( ) is issued without the optional cTableAlias or nWorkArea arguments.
Remarks
Visual FoxPro uses field state values to determine which fields in tables or cursors are updated. SETFLDSTATE( ) makes it possible for you to control which fields Visual FoxPro attempts to update, regardless of which fields have been modified in the table or cursor.
Example
The following example demonstrates how you can use SETFLDSTATE( ) to change the field status. 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.
SETFLDSTATE( ) is used to change the field status of the cust_id
field back to 1 (unmodified). GETFLDSTATE( ) is issued again and displays 1, corresponding to the state of the cust_id
field assigned by SETFLDSTATE( ). TABLEREVERT( ) is used to return the table to its original state.
CLOSE DATABASES
SET MULTILOCKS ON && Must be on for table buffering
SET PATH TO (HOME(2) + 'Data\') && Sets path to database
OPEN DATABASE testdata && Open testdata database
USE Customer && Open customer table
= CURSORSETPROP('Buffering', 5, 'customer') && Enable table buffering
CLEAR
? GETFLDSTATE('cust_id') && Displays 1, not modified
REPLACE cust_id WITH '***' && Changes field contents
? GETFLDSTATE('cust_id') && Returns 2, field modified
= SETFLDSTATE('cust_id', 1) && Change the field status
? GETFLDSTATE('cust_id') && Displays 1, not modified
= TABLEREVERT(.T.) && Discard all table changes