Prepare for edit

Command group Flag affected Reversible Execute on client Platform(s)
Changing data YES YES NO All

Syntax

Prepare for edit

Description

This command prepares Omnis for editing data. It brings records into memory ready for updating and rereads the current records when in multi-user mode in case another user has made a change to a record since it was read in. Your method can then alter the values of the records. The contents of the current record buffer are not written back to disk until Update files is encountered.

If there is a window open and you require data to be entered via that window, Enter data is required after the Prepare for edit.

Prepare for edit/insert mode is cleared only by a Cancel prepare for update, Update files or Quit all methods command. You can build lists, print reports and change the main file in the middle of an update without cancelling the Prepare for... mode.

Multi-user considerations

Records in the current record buffer from Read/write files will be locked when Prepare for edit is executed, so as to prevent simultaneous editing of a record. The lock is removed by Update files or any command which cancels the Prepare for mode.

If Wait for semaphores is active, a Prepare for edit will wait for a record to become available if another workstation has locked it. If the user presses Ctrl-Break/Ctrl-C/Cmnd-period while waiting for access, the command fails and processing halts. With Do not wait for semaphores active, a record lock returns control to the method with the flag false.

In the following method, the Edit mode is used to process the whole of a file. Enter data is not used as no user intervention is required. Update files writes data to the disk and clears the Prepare for.. mode and record locks.

Example

; The following example is equivalent to the 'edit record' on the commands menu which can be
; installed using 'Install menu *Commands'
Prepare for edit
Enter data
If flag true
  Update files
Else
  Clear main & connected
  Redraw {wMyWindow}
End If
; In the following method, the Edit mode is used to process the whole of a file. Enter data
; is not used as no user intervention is required. Update files writes data to the disk and
; clears the Prepare for.. mode and record locks.
; In ‘Wait for semaphores’ mode:
Set main file {fAccounts}
Find first on fAccounts.Code
While flag true
  Prepare for edit
  Calculate fAccounts.Balance as fAccounts.Balance-10
  Update files
  Next
End While
; In ‘Do not wait for semaphores’ mode:
Set main file {fAccounts}
Find first on fAccounts.Code
While flag true
  Repeat
    Prepare for edit
  Until flag true
  Calculate fAccounts.Balance as fAccounts.Balance-10
  Repeat
    Update files
  Until flag true
  Next
End While
; In the next Edit example, the Enter data command is included in the method so that the user
; can edit the record from the keyboard. Again, the command Update files cancels the Prepare
; for update mode and writes data to the disk.
Prepare for edit
Enter data
Update files if flag set
; The next example has been written to control record locking by preventing Omnis from waiting
; for a record lock. It takes the form of general purpose 'prepare for edit' which you can
; call with a number which tells it how many times to try for a lock if the record is locked by
; another user.
; general Prepare for edit
; declare Parameter lTries (Number Long Integer)
Do not wait for semaphores
Calculate lCount as 1
Repeat
  Prepare for edit
  Calculate lCount as lCount+1
Until #F|(lCount>lTries)
; Keeps trying until flag true OR counter>TRIES
Wait for semaphores