PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US

  • The lock was not performed
  • Locking a file
  • Position in the file
  • Operating mode in Windows Vista (and later)
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
Entirely or partially locks an external file. The file will be unlocked:
  • by fUnlock,
  • when the file is closed.
The application that locked the file can read this file and write into this file. The other applications cannot read this file or write into this file.
Versions 18 and later
Universal Windows 10 App This function is now available in Windows Store apps mode.
New in version 18
Universal Windows 10 App This function is now available in Windows Store apps mode.
Universal Windows 10 App This function is now available in Windows Store apps mode.
Versions 21 and later
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
New in version 21
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
// Open an external file
FileID = fOpen("C:\MyDirectories\File.txt", foReadWrite)
IF FileID <> -1 THEN
...
// Lock the external file
ResLock = fLock(FileID)
...
END
Syntax
<Result> = fLock(<File Identifier> [, <First Byte to Lock> [, <Number of Bytes to Lock>]])
<Result>: Boolean
  • True if the file was locked,
  • False otherwise.
<File Identifier>: Integer
Identifier of the file to lock, defined by fOpen or fCreate.
<First Byte to Lock>: Optional integer
Position of the first byte to lock (0 corresponds to the first byte of the file).
<Number of Bytes to Lock>: Optional constant or integer
  • Number of bytes to lock in the file.
  • Constant:
    fLockEmptyFilefLock has the same behavior, no matter whether the file is empty or not (see the notes).
Remarks

The lock was not performed

fLock returns False if the file was not locked. The lock can be performed only if:
  • the external file is opened,
  • the file identifier is valid,
  • the file or the bytes to lock are not already locked by another computer or by another application.

Locking a file

  • The file is entirely locked if <First Byte to Lock> and <Number of Bytes to Lock> are not specified.
  • The file is locked from the first byte to lock (<First Byte to Lock>) until the end if <Number of Bytes to Lock> is not specified.
  • By default, fLock locks no byte if the file is empty. In this case, several applications can successfully "lock" an empty file. However, the file cannot be overwritten as long as the lock is performed.
To have the same behavior regardless whether the file is empty or not, use the fLockEmptyFile constant.
Linux The lock is effective between two different sites or contexts. Unlike Windows, a process cannot lock a file that was previouly locked.

Position in the file

When opening a file, the current position corresponds to:
  • the first byte of the file (by default),
  • the last byte of the file is the file is opened in "addition" mode (foAdd constant).
This position can be modified by fSeek.
The current position is not modified by the use of fLock.
WINDEVWEBDEV - Server codeReports and QueriesUser code (UMC)

Operating mode in Windows Vista (and later)

If this function does not operate properly in Windows Vista (and later), check whether the file used is not found in one of the system directories (Windows directory or "Program Files" directory).
Indeed, in Windows Vista (and later), with the UAC mechanism (User Account Control) enabled, you must have the administrator privileges to handle and/or modify the files found in the system directories (Windows directory or "Program Files" directory).
Programming tip: To handle and/or modify the files without having administrator privileges, you should:
  • avoid writing into the Windows directory or into the "Program Files" directory,
  • use the system directory corresponding to the application (returned by SysDir associated with the srCommonAppData constant).
Related Examples:
Handling text files Unit examples (WINDEV): Handling text files
[ + ] Handling "text" files with WINDEV:
- Create a text file
- Write into a text file
- Read in a text file
Handling text files Unit examples (WEBDEV): Handling text files
[ + ] This example explains how to handle "non HFSQL" files with WEBDEV and it allows you to:
- Create a text file
- Write into a text file
- Read in a text file
Components
WINDEVWEBDEV - Server codeReports and Queries wd230std.dll
Linux wd230std.so
Minimum required version
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment