FOpen Function (String) | |
Open a file.
Namespace:
XSharp.Core
Assembly:
XSharp.Core (in XSharp.Core.dll) Version: 2.19
Syntax FUNCTION FOpen(
cFileName AS STRING
) AS IntPtr
public static IntPtr FOpen(
string cFileName
)
Request Example
View SourceParameters
- cFileName
- Type: String
The file name, including an optional drive, directory, and extension. SetDefault() and SetPath() settings are ignored; the Windows default is used unless you specify a drive and directory as part of the file name. No extension is assumed.
This function sets NetErr() in case of a concurrency control conflict.
Return Value
Type:
IntPtr
The file handle of the opened file in the range of 0 to 32,767.
This value is similar to an alias in the database system and is required to identify the open file to other file functions.
It is, therefore, important to assign the return value to a variable for later use, as in the example below.
If an error occurs, FOpen() returns F_ERROR. FError() can be used to determine the specific error.
Remarks
FOpen() is a low-level file function that opens an existing file for reading and writing, depending on the kMode argument.
Note that in order for two processes to use the same file simultaneously, both files should be opened in FO_SHARED sharing mode.
Whenever there is an error, FError() can be used to determine the specific error.
For example, if the file does not exist, FOpen() returns F_ERROR and FError() returns 2 to indicate that the file was not found.
Examples
This example uses FOpen() to open a file with sharable read/write status and displays an error message if the open fails:
1ptrHandle := FOpen("temp.txt")
2IF ptrHandle = F_ERROR
3 ? DOSErrString(FError())
4ENDIF
This example uses FOpen() to open a file with an optional retry if FOpen() fails:
1FUNCTION NetOpen(cFile AS STRING,;
2 wMode AS DWORD, wSeconds AS DWORD);
3 AS LOGIC PASCAL
4 LOCAL lForever AS LOGIC
5
6 lForever := (wSeconds = 0)
7 DO WHILE (lForever .OR. wSeconds > 0)
8 IF FOpen(cFile, wMode) != F_ERROR
9 RETURN TRUE
10 ENDIF
11 InKey(1)
12 wSeconds -= 1
13 ENDDO
14 RETURN FALSE
See Also