THYFile

Overview

The THYFile class provides a convenient and object oriented way to access disk files.

Although it can be used independently, THYFile instances are usually returned by the THYDirectory class.

Methods such as Open, Close, Copy, CopyFromStream, etc. are wrappers around VCL functions that don't encapsulate such behavior and helps the developer to use a structured programming approach.

Location


 

constructor Create (THYDirectory, TSearchRec)  overload virtual    (declared in THYCustomFile)

Creates a new instance of the class.

constructor Create(aParent: THYDirectory; aSearchRec: TSearchRec)

Parameters:

  • aParent: Reference to a parent directory.
  • aSearchRec: Pointer to a TSearchRec structure.

constructor Create (THYDirectory, string)  overload    (declared in THYCustomFile)

Creates a new instance of the class.

constructor Create(aParent: THYDirectory; const aName: string)

Parameters:

  • aParent: Reference to a parent directory.
  • aName: Name of the item.

constructor CreateNew

Creates a new instance of the class and creates a new file.

constructor CreateNew(aParent: THYDirectory; const aName: string; KeepOpen: Boolean)

Parameters:

  • aParent: Reference to a parent directory.
  • aName: Name of the new file.
  • KeepOpen: Specifies whether new file will remain open.

Attributes    (declared in THYCustomFile)

Gets or sets file attributes. Attributes values is a standard delphi values for TSearchRec.

property Attributes: Integer read write

AttributesString    (declared in THYCustomFile)

Gets string representation of the file attributes.

property AttributesString: string read

CheckOpen  protected

Check whether file is open.

procedure CheckOpen(MustBeOpen: Boolean)

Parameters:

  • MustBeOpen: Value that indicates whether file should already be opened.

Close

Closes the file.

procedure Close

Copy

Copies the file to a specified location.

procedure Copy(aDestination: string)

Parameters:

  • aDestination: New location of the file.

CopyFromStream

Copies data form the specified stream into the current file.

function CopyFromStream(aSource: TStream; aCount: Integer): Integer

Parameters:

  • aSource: Reference to a stream.
  • aCount: Number of bytes to copy.

CopyToStream

Copies file content to the specified stream.

function CopyToStream(aDestination: TStream; aCount: Integer): Integer

Parameters:

  • aDestination: Reference to a stream.
  • aCount: Number of bytes to copy.

Data    (declared in THYCustomFile)

Gets or sets pointer to a custom data associated with the file.

property Data: pointer read write

Delete

Deletes the file.

procedure Delete

Directory    (declared in THYCustomFile)

Gets reference to a parent directory.

property Directory: THYDirectory read

FullName    (declared in THYCustomFile)

Gets full path of the file.

property FullName: string read

GetFullName  protected virtual    (declared in THYCustomFile)

Returns full path of the file.

function GetFullName: string

GetSize  protected override

Returns size of the file.

function GetSize: Integer

Handle

Gets handle of the file.

property Handle: Integer read

IsOpen

Gets a value which idicates whether file is open.

property IsOpen: Boolean read

Name    (declared in THYCustomFile)

Gets or sets name of the file.

property Name: string read write

Open

Opens the file with specified mode.

procedure Open(aFileMode: cardinal)

Parameters:

  • aFileMode: Value that indicates how the file is to be opened. Takes standard value of the TFileStream open modes.

Position

Gets or sets current position in the underlying file stream.

property Position: Integer read write

Size    (declared in THYCustomFile)

Gets size of the file.

property Size: Integer read

Stream

Gets reference to the underlying file stream.

property Stream: TFileStream read

Time    (declared in THYCustomFile)

Gets or sets file time.

property Time: TDateTime read write

Version    (declared in THYCustomFile)

Gets string representation of the file version.

property Version: string read

 

Attributes    (declared in THYCustomFile)

Gets or sets file attributes. Attributes values is a standard delphi values for TSearchRec.

property Attributes: Integer read write

AttributesString    (declared in THYCustomFile)

Gets string representation of the file attributes.

property AttributesString: string read

Data    (declared in THYCustomFile)

Gets or sets pointer to a custom data associated with the file.

property Data: pointer read write

Directory    (declared in THYCustomFile)

Gets reference to a parent directory.

property Directory: THYDirectory read

FullName    (declared in THYCustomFile)

Gets full path of the file.

property FullName: string read

Handle

Gets handle of the file.

property Handle: Integer read

IsOpen

Gets a value which idicates whether file is open.

property IsOpen: Boolean read

Name    (declared in THYCustomFile)

Gets or sets name of the file.

property Name: string read write

Position

Gets or sets current position in the underlying file stream.

property Position: Integer read write

Size    (declared in THYCustomFile)

Gets size of the file.

property Size: Integer read

Stream

Gets reference to the underlying file stream.

property Stream: TFileStream read

Time    (declared in THYCustomFile)

Gets or sets file time.

property Time: TDateTime read write

Version    (declared in THYCustomFile)

Gets string representation of the file version.

property Version: string read

 

constructor Create (THYDirectory, TSearchRec)  overload virtual    (declared in THYCustomFile)

Creates a new instance of the class.

constructor Create(aParent: THYDirectory; aSearchRec: TSearchRec)

Parameters:

  • aParent: Reference to a parent directory.
  • aSearchRec: Pointer to a TSearchRec structure.

constructor Create (THYDirectory, string)  overload    (declared in THYCustomFile)

Creates a new instance of the class.

constructor Create(aParent: THYDirectory; const aName: string)

Parameters:

  • aParent: Reference to a parent directory.
  • aName: Name of the item.

constructor CreateNew

Creates a new instance of the class and creates a new file.

constructor CreateNew(aParent: THYDirectory; const aName: string; KeepOpen: Boolean)

Parameters:

  • aParent: Reference to a parent directory.
  • aName: Name of the new file.
  • KeepOpen: Specifies whether new file will remain open.

CheckOpen  protected

Check whether file is open.

procedure CheckOpen(MustBeOpen: Boolean)

Parameters:

  • MustBeOpen: Value that indicates whether file should already be opened.

Close

Closes the file.

procedure Close

Copy

Copies the file to a specified location.

procedure Copy(aDestination: string)

Parameters:

  • aDestination: New location of the file.

CopyFromStream

Copies data form the specified stream into the current file.

function CopyFromStream(aSource: TStream; aCount: Integer): Integer

Parameters:

  • aSource: Reference to a stream.
  • aCount: Number of bytes to copy.

CopyToStream

Copies file content to the specified stream.

function CopyToStream(aDestination: TStream; aCount: Integer): Integer

Parameters:

  • aDestination: Reference to a stream.
  • aCount: Number of bytes to copy.

Delete

Deletes the file.

procedure Delete

GetFullName  protected virtual    (declared in THYCustomFile)

Returns full path of the file.

function GetFullName: string

GetSize  protected override

Returns size of the file.

function GetSize: Integer

Open

Opens the file with specified mode.

procedure Open(aFileMode: cardinal)

Parameters:

  • aFileMode: Value that indicates how the file is to be opened. Takes standard value of the TFileStream open modes.

 

  • THYDirectory
  • THYDirectoryManager