System.Classes.TBinaryReader.Create

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

constructor Create(Stream: TStream; AEncoding: TEncoding = nil; AOwnsStream: Boolean = False); overload;
constructor Create(const Filename: string; Encoding: TEncoding = nil); overload;

C++

__fastcall TBinaryReader(TStream* Stream, System::Sysutils::TEncoding* AEncoding, bool AOwnsStream)/* overload */;
__fastcall TBinaryReader(const System::UnicodeString Filename, System::Sysutils::TEncoding* Encoding)/* overload */;

Properties

Type Visibility Source Unit Parent
constructor public
System.Classes.pas
System.Classes.hpp
System.Classes TBinaryReader

Description

Creates a TBinaryReader instance.

Use Create to create and initialize a TBinaryReader instance.

There are 3 overloaded Create methods:

  • The first method has 2 parameters: Stream, the stream from which TBinaryReader will read, and the AEncoding stream encoding. AEncoding is set by default to nil for Delphi.
  • The second method has 3 parameters: Stream, AEncoding, and AOwnsStream. The first two are those described earlier, while AOwnsStream is used to specify whether the stream is owned by TBinaryReader or not (in which case it can be used by other instances of other classes.)
  • The third method also has 2 parameters: Filename, which represents a file name, and Encoding, which represents the encoding of the file. This method creates a stream for the file Filename. An exception is raised when the file is not found.

For example, if we have the ABinaryReader TBinaryReader instance and the file AFile.dat, which has UTF8 encoding, the code should look like this (for Delphi):

ABinaryReader := TBinaryReader.Create('AFile.dat', TEncoding.UTF8);

Note: When using strings and characters, you should use the TEncoding.Unicode encoding. Otherwise, an exception is raised when TBinaryReader will try to read from the stream.


See Also

Code Examples