AYUDA EN LÍNEA
 WINDEVWEBDEV Y WINDEV MOBILE

Ayuda / WLanguage / Funciones WLanguage / Funciones estándar / Funciones de archivos externos
  • 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
Versión mínima requerida
  • Versión 9
Esta página también está disponible para…
Comentarios
Haga clic en [Agregar] para publicar un comentario

Última modificación: 24/08/2022

Señalar un error o enviar una sugerencia | Ayuda local