| [Overview][Constants][Types][Classes][Procedures and functions][Variables][Index] | 
Open an existing file and return a file handle
Source position: filutilh.inc line 171
function FileOpen(  | 
const FileName: unicodestring;  | 
Mode: Integer  | 
):THandle;  | 
const FileName: RawByteString;  | 
Mode: Integer  | 
):THandle;  | 
FileOpen opens a file with name FileName with mode Mode. Mode can be one of the following constants:
Under Windows and Unix, the above mode can be or-ed with one of the following sharing/locking flags:
If the file has been successfully opened, it can be read from or written to (depending on the Mode parameter) with the FileRead and FileWrite functions.
| Remark: | Remark that you cannot open a file if it doesn't exist yet, i.e. it will not be created for you. If you want tp create a new file, or overwrite an old one, use the FileCreate function. | 
There are some limitations to the sharing modes.
For an example, see FileCreate
On Error, THandle(-1) is returned.
  | 
Open file in read-only mode  | 
|
  | 
Open file in write-only mode  | 
|
  | 
Open file in read/write mode.  | 
|
  | 
Lock file so other processes can only read.  | 
|
  | 
Lock file for exclusive use  | 
|
  | 
Lock file so other processes cannot read.  | 
|
  | 
Do not lock file.  | 
|
  | 
Open file in DOS share-compatibility mode  | 
|
  | 
Close a file handle.  | 
|
  | 
Write data from a buffer to a given file handle.  | 
|
  | 
Create a new file and return a handle to it.  | 
|
  | 
Read data from a file handle in a buffer.  | 
|
  | 
Truncate an open file to a given size.  | 
|
  | 
Set the current file position on a file handle.  |