System.SysUtils.FileCreate

提供: RAD Studio API Documentation
移動先: 案内検索

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 DELPHI_PACKAGE Winapi::Windows::THandle __fastcall FileCreate(const System::UnicodeString FileName)/* overload */;

プロパティ

種類 可視性 ソース ユニット
function public
System.SysUtils.pas
System.SysUtils.hpp
System.SysUtils System.SysUtils


説明

新しいファイルを作成します。

FileCreate は指定した名前で新しいファイルを作成します。 戻り値が INVALID_HANDLE_VALUE ではない場合、関数が成功し、その値が開かれたファイルのファイル ハンドルであることを意味します。 戻り値が INVALID_HANDLE_VALUE であれば、エラーが発生したことを示します。

FileCreate の戻り値型は、Delphi 2010 以降、Integer 型から THandle に変更されました。

 var
   MyFile: THandle;
 begin
   MyFile := FileCreate('C:\temp\bla.txt');
   if MyFile = INVALID_HANDLE_VALUE then
     raise Exception.Create('File already exists');
 end;

以前の動作を維持するには、FileCreate の戻り値を NativeInt にキャストします。この場合、戻り値 -1 がエラーを表します。 次のコードでは、そのやり方の例を示しています。

var
  MyFile: Integer; // for 32bit platform.
begin
  MyFile := NativeInt(FileCreate('C:\temp\bla.txt'));
  if MyFile = -1 then
    raise Exception.Create('File already exists');
end;
メモ: Rights パラメータは、Mode に fmCreate が含まれている際に、Windows 以外のプラットフォームで使用されます。 詳細については、プラットフォーム専用の “open” システムコールの説明を参照してください。 例: Linux マニュアル ページ

関連項目

コード例