constructor Create(Stream: TStream; AEncoding: TEncoding = nil; AOwnsStream: Boolean = False); overload; constructor Create(const Filename: string; Encoding: TEncoding = nil); overload;
__fastcall TBinaryReader(TStream* Stream, System::Sysutils::TEncoding* AEncoding, bool AOwnsStream)/* overload */; __fastcall TBinaryReader(const System::UnicodeString Filename, System::Sysutils::TEncoding* Encoding)/* overload */;
Creates 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
AEncodingis set by default to
- The second method has 3 parameters:
AOwnsStream. The first two are those described earlier, while
AOwnsStreamis 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.