Show: Delphi C++
Display Preferences

System.SysUtils.FileCreate

From XE2 API Documentation
Jump to: navigation, search

Delphi

function FileCreate(const FileName: string): THandle;
function FileCreate(const FileName: string; Rights: Integer): THandle;
function FileCreate(const FileName: string; Mode: LongWord; Rights: Integer): THandle;

C++

extern PACKAGE unsigned __fastcall FileCreate(const System::UnicodeString FileName)/* overload */;

Contents

Properties

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

Description

Creates a new file.

FileCreate creates a new file with the specified name. If the return value is positive, the function was successful and the value is the file handle of the new file. A return value of INVALID_HANDLE_VALUE indicates that an error occurred.

The return type for FileCreate has changed from Int to THandle. To emulate the previous behavior, you could cast the FileCreate return value into a System.NativeInt, and then a return value of -1 indicates an error. Here is a code snippet demonstrating how to do this.

var
  MyFile: NativeInt;
begin
  MyFile := NativeInt(FileCreate('C:\temp\bla.txt'));
  if MyFile = -1 then
    raise Exception.Create('File already exists');
end:
Note: On Windows, the FileAccessRights variable and Rights parameter are ignored.

See Also

Code Examples

Personal tools
Previous Versions
Translations