System.SysUtils.FileOpen

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

function FileOpen(const FileName: string; Mode: LongWord): THandle;

C++

extern DELPHI_PACKAGE Winapi::Windows::THandle __fastcall FileOpen(const System::UnicodeString FileName, System::LongWord Mode);

Properties

Type Visibility Source Unit Parent
function public
System.SysUtils.pas
System.SysUtils.hpp
System.SysUtils System.SysUtils

Description

FileOpen opens a specified file using a specified access mode.

Use FileOpen to open a file and obtain a file handle. The Mode parameter indicates how the file is opened. The Mode parameter consists of an open mode and (possibly) a share mode or'ed together.

For open mode constants you must use one of the following values.

Value Meaning

fmExclusive

Automatically creates the file only if it does not exist, otherwise fails.

fmOpenRead

Open the file for reading only.

fmOpenWrite

Open the file for writing only. Writing to the file completely replaces the current contents.

fmOpenReadWrite

Open the file to modify the current contents rather than replace them.

For share mode constants you must use one of the following values.

Value Meaning

fmShareCompat

Sharing is compatible with the way FCBs are opened.

fmShareExclusive

Other applications cannot open the file for any reason.

fmShareDenyWrite

Other applications can open the file for reading, but not for writing.

fmShareDenyRead

Other applications can open the file for writing, but not for reading.

fmShareDenyNone

No attempt is made to prevent other applications from reading from or writing to the file.

FileOpen can return:

  • A different value from INVALID_HANDLE_VALUE, meaning that the function was successful and the value is the file handle of the opened file.
  • A value equal to INVALID_HANDLE_VALUE, indicating that an error has occurred.
Note: We do not encourage using non-native Delphi language file handlers such as FileOpen. These routines map to system routines and return OS file handles, not normal Delphi file variables. These are low-level file access routines. For normal file operations use AssignFile, Rewrite, and Reset instead.

See Also

Code Examples