TBinaryReader

TBinaryReader

uses
  SysUtils,
  Classes;

// Using BinaryReader
procedure ReadBinary(filename: string);
var
  AFile: TFileStream;
  BR: TBinaryReader;
  AInteger: Integer;
  ADouble: Double;
  AChar: Char;
  AString: String;
begin
  AFile := TFileStream.Create(filename, fmOpenRead);
  BR := TBinaryReader.Create(AFile, TEncoding.Unicode, false);
  try
    // read an integer and write it to the console
    AInteger := BR.ReadInteger;
    Writeln(AInteger);

    // read a double and write it to the console
    ADouble := BR.ReadDouble;
    Writeln(ADouble);

    // read a char and write it to the console
    AChar := BR.ReadChar;
    Writeln(AChar);
    // read a string and write it to the console
    AString := BR.ReadString;
    Writeln(AString);

    BR.Close;
  finally

    BR.Free;
    AFile.Free;
  end;

end;

  

posted @ 2020-09-08 22:20  delphi中间件  阅读(354)  评论(0编辑  收藏  举报