UNLOCK statement


Remove locks placed on a file to permit other threads, processes, and applications to access the locked sections of the file.


UNLOCK [#] filenum& [, {record&& | start&& TO finish&&}]


UNLOCK restores access to a record, range of records, byte, or range of bytes locked by the LOCK statement, in file opened as file number filenum&.

If the file was opened in random-access mode, record&&, start&&, and finish&& specify record numbers.

When used with binary mode files, record&&, start&&, and finish&& specify byte positions, starting from either one (the default) or zero, depending on the BASE setting given when the file was Opened.

If a record is specified, only that record (or byte) is unlocked.  Otherwise, a range of records (or bytes) is unlocked, from start&& to finish&&. If no records are specified, or if the file was opened in sequential mode, the entire file is unlocked.

All records (or bytes) to be unlocked must have been previously locked using the LOCK statement.  Multiple locks may be placed on a file, and locks may be unlocked in any order.  However, the parameters used for each UNLOCK statement must exactly match those used for the previous corresponding LOCK statement.

All locked records (or bytes) must be unlocked using the UNLOCK statement before the file can be closed.

If an unlock attempt fails, PowerBASIC sets the ERR system variable to reflect a run-time Error 70 ("Permission denied"), or Error 75 ("Path/file access error").

See also



See the example for LOCK.