File.Open

Top  Previous  Next

 

Syntax

function File.Open(Filename: string; FileMode: integer): pointer

 

Alternative Names

ibec_fs_OpenFile

 

Description

Opens or creates a file with the given Filename.

 

If there's a "encoding preamble" available in the file, the detected character encoding will be used for reading and writing text.

 

If you create a file with this function, there will be no encoding, you can use File.Create to create a file with a character encoding.

 

The FileMode parameter is one of the following:

__fmCreate

Create a file, if the file already exists, overwrite the file. The stream is opened in write mode.

__fmOpenRead

Open a file for reading only.

__fmOpenWrite

Open a file for writing only.

__fmOpenReadWrite

Open a file for reading and writing, replacing the contents instead of the file itself.

 

The following additional options are available and can be combined with the previous options:

__fmShareCompat

Sharing is compatible with the way file control blocks are opened.

__fmShareExclusive

Other applications cannot open the file.

__fmShareDenyWrite

Other applications can open the file for reading only.

__fmShareDenyRead

Other applications can open the file for writing only.

__fmShareDenyNone

Other applications can read and write the file while the current application is doing the same.

 

The Return value is a file-stream pointer that can be used for additional calls. If creating or opening of the file fails, NULL is returned.

 

See also

File.Close

 

Example

execute udsblock

as

begin

  /* open text file with UTF8 encoding preamble */ 

  fs = File.Open('c:\data\utf8text.txt', __fmOpenReadWrite + __fmShareDenyWrite);

  try

    /* read a single line of text */

    valueout = File.ReadLn(fs);

  finally

    File.Close(fs);

  end

end