ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Standard functions / External file functions
  • Example 1: Locking a block of bytes in an external file
  • Example 2: Locking an entire external file
Example 1: Locking a block of bytes in an external file
The following code is used to lock a block of bytes (50 bytes) in a text file. The text file is opened in read/write. The locked part will be accessible in read/write by the application that locks this file.
// Declare and initialize the variables
FileNameAndPath is string
FileID is int
ResLock is boolean = True
ResUnlock is boolean = True
ResCloseFile is int
 
// Select the file name and path
FileNameAndPath = "C:\DOC\EXAMPLE.TXT"
 
// Open file
FileID = fOpen(FileNameAndPath, foReadWrite)
 
// Display an error message if the opening was not performed
IF FileID = -1 THEN
Error(ErrorInfo(errMessage))
ELSE
// Lock a 50-byte block
ResLock = fLock(FileID, 0, 49)
// Display an error message if the lock operation failed
IF ResLock = False THEN
Error(ErrorInfo(errMessage))
ELSE
// Processes in the locked block of bytes
...
// End of processes in the locked block of bytes
END
// Unlock the block of bytes
ResUnlock = fUnlock(FileID, 0, 49)
// Display an error message if the unlock operation failed
IF ResUnlock = False THEN Error(ErrorInfo(errMessage))
// Close the file
ResCloseFile = fClose(FileID)
IF ResCloseFile = -1 THEN
// Display an error message if the closing was not performed
Error(ErrorInfo(errMessage))
END
END
Example 2: Locking an entire external file
The following code is used to lock the entire text file. The file is opened in read/write mode. The locked file will be accessible in read/write by the application that locks this file.
// Declare the variables
FileNameAndPath is string
FileID is int
ResLock is boolean
ResCloseFile is int
 
// Select the file name and path
FileNameAndPath = "C:\DOC\EXAMPLE.TXT"
 
// Open file
FileID = fOpen(FileNameAndPath, foReadWrite)
 
// Display an error message if the opening was not performed
IF FileID = -1 THEN
Error(ErrorInfo(errMessage))
ELSE
// Lock the file
ResLock = fLock(FileID)
// Display an error message if the lock operation failed
IF ResLock = False THEN
Error(ErrorInfo(errMessage))
ELSE
// Processes in the locked file
...
// End of processes in the locked file
END
// Close the file
// Closing the file will automatically unlock it
ResCloseFile = fClose(FileID)
IF ResCloseFile = -1 THEN
// Display an error message if the closing was not performed
Error(ErrorInfo(errMessage))
END
END
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 08/24/2022

Send a report | Local help