次の方法で共有


How to: Perform Updates Using Buffers

After choosing the buffering method and the type of locking, you can enable record or table buffering.

To enable buffering

  • Choose one of the following options:

    • In the Form Designer, set the BufferModeOverride property of the cursor in the data environment of the form.

    -OR-

    • Use the CURSORSETPROP( ) function to set the Buffering property.

For example, you can enable pessimistic row buffering by placing the following code in the Init procedure of a form:

CURSORSETPROP('Buffering', 2)

You then place code for the update operations in the appropriate method code for your controls.

To write edits to the original table, use the TABLEUPDATE( ) Function. To cancel edits after a failed update operation in a table constrained by rules, use TABLEREVERT( ) Function, which is valid even if explicit table buffering is not enabled. To specify a level of table integrity checking lower than the default setting, you can use the SET TABLEVALIDATE Command.

The following sample demonstrates how to update records when pessimistic record buffering is enabled.

Example of Updating Using Record and Table Buffers

Code

Comment

OPEN DATABASE testdata

USE customers

CURSORSETPROP('Buffering', 2)

In the form Init code, open the table and enable pessimistic record buffering.

lModified = .F.

FOR nFieldNum = 1 TO FCOUNT()

IF GETFLDSTATE(nFieldNum) = 2

lModified = .T.

EXIT

ENDIF

ENDFOR

Go through fields, checking for any field that's been modified.

Note

This code might be in the Click event of a "Save" or "Update" command button.

IF lModified

nResult = MESSAGEBOX;

("Record has been modified. Save?", ;

4+32+256, "Data Change")

Locate the next modified record.

IF nResult = 7

TABLEREVERT (.F.)

ENDIF

ENDIF

Present the current value and give the user the option to revert the change to the current field.

SKIP

IF EOF()

MESSAGEBOX( "already at bottom")

SKIP -1

ENDIF

THISFORM.Refresh

SKIP guarantees that the last change is written.

See Also

Concepts

Buffering Data

Managing Conflicts When Updating Data

Reference

Update Criteria Tab, View Designer

DBSETPROP( ) Function

CURSORSETPROP( ) Function

Other Resources

Updating Data

Programming for Shared Access