Equinox Online Help - Language Reference - A to Z

Home

FileLock

Applies to
SyntaxFileLock HandleItem, StartExpression, LengthExpression
Action[Statement] Locks a specified number of bytes in a random file.
ScopeUsable anywhere.
Notes

This statement allows you to lock bytes in a file, preventing access by another user on a network. LengthExpression number of bytes are locked, starting at StartExpression. The first byte of the file is byte number 1. To lock the entire file, supply StartExpression as 1 and LengthExpression as -1. To test if a section of the file is locked, attempt the read or write operation required and examine the error return.

This statement will not work if the file has been opened as a sequential file. File sharing must be enabled in the operating system.

The system workarea SysError is set to 2 if the lock attempt fails, 1 if an error occurs, otherwise zero.

CategoryFile IO
See Also FileClose, FileCloseAll, FileDelimiters, FileInput, FileInputLine, FileLock, FileMovePosition, FileOpen, FilePosition, FilePrint, FileRead, FileReadLine, FileReadBinary, FileReadFile, FileUnlock, FileWrite, FileWriteBinary, FileWriteFile
Example

This method opens a file with sharing enabled, locks some bytes, reads them and then unlocks them.

string Buffer
handle hnd

| Open the file
FileOpen "MYDATA.DAT", RandomReadOnly + DenyNone, hnd

if hnd = -1 then
Alert "File Opening Error."
exit method
end if

| Lock the first 30 bytes
FileLock hnd, 1, 30

if syserror then
Alert "File Locking Error."
exit method
end if


FileReadString hnd, Buffer, 30

if syserror then
Alert "File Reading Error."
exit method
end if

| Unlock the first 30 bytes
FileUnlock hnd, 1, 30

if syserror then
Alert "File Unlocking Error."
exit method
end if

| . . and close the file
FileClose hnd