Typed Files

Top  Previous  Next

What is translated > File Input and Output > Typed Files

A Delphi declaration of the form file of T is translated to TypedFile<T>.

 

A typed file stores a sequence of values with a fixed record size.

 

For example, a Delphi file of Word is translated to:

 

TypedFile<ushort> myFile =

    TypedFile<ushort>.CreateRecord();

 

The record size is determined from the element type. For ushort, the record size is two bytes.

 

A typed file is written as follows:

 

AssignFile(myFile, "Words.dat");

Rewrite(myFile);

 

Write(myFile, (ushort)234);

Write(myFile, (ushort)567);

 

CloseFile(myFile);

 

The file can later be reopened and read:

 

ushort value = 0;

 

Reset(myFile);

 

while (!Eof(myFile))

{

    Read(myFile, ref value);

}

 

CloseFile(myFile);

 

TypedFile<T> requires a fixed-size value type. Types containing managed references, such as strings, dynamic arrays, classes, objects, or interfaces, cannot be stored directly.

 

When binary compatibility with Delphi is required, the generated C# record layout must match the original Delphi record layout.

 

 



This page belongs to the Delphi2C# Documentation

Delphi2C# home  Content