Assigning, Opening, and Closing Files

Top  Previous  Next

What is translated > File Input and Output > Assigning, Opening, and Closing Files

AssignFile associates a file variable with a file name. It does not open the file.

 

AssignFile(myFile, "Test.txt");

 

Rewrite creates or replaces a file and opens it for writing.

 

Rewrite(myFile);

 

For an untyped file, an optional record size can be supplied:

 

Rewrite(myFile, 1);

 

Append opens a text file and positions the writer at the end of the file.

 

Append(myFile);

 

Reset opens an existing file for reading.

 

Reset(myFile);

 

For typed and untyped files, Reset uses the current Delphi FileMode setting to determine the access and sharing mode.

 

CloseFile closes the current reader, writer, or stream.

 

CloseFile(myFile);

 

CloseFile preserves the file name assigned by AssignFile. The same file variable can therefore be reopened:

 

AssignFile(myFile, "Test.txt");

 

Rewrite(myFile);

CloseFile(myFile);

 

Reset(myFile);

CloseFile(myFile);

 

Rename changes the physical file name and updates the name stored in the file variable.

 

Rename(myFile, "NewName.txt");

 

The file must be closed before Rename is called.

 

Delphi2CSharp does not generate a C# using block for Delphi file operations. This avoids the need to locate a matching CloseFile call while translating the source.



This page belongs to the Delphi2C# Documentation

Delphi2C# home  Content