Home  |  Delphi .net Home  |  System.IO.BinaryReader  |  Close Method
  
Close  
Method  
Closes the BinaryReader
BinaryReader Class
System.IO NameSpace
CF1.  Procedure Close ;
CF : Methods with this mark are Compact Framework Compatible
Description
Closes the reader by calling the Dispose method.
Microsoft MSDN Links
System.IO
System.IO.BinaryReader
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 
 
Closing a BinaryWriter and BinaryReader
program Project1;
{$APPTYPE CONSOLE}

uses
  System.IO;

var
  MyFileStream  : System.IO.FileStream;
  MyFileWriter  : System.IO.BinaryWriter;
  MyFileReader  : System.IO.BinaryReader;
  CharAsByte    : Byte;

begin
  // Create and open our binary file as a stream
  MyFileStream := System.IO.File.Open('C:DelphiBasics.txt',
                                      System.IO.FileMode.Create);

  // Create a BinaryWriter to allow writing to this file
  MyFileWriter := System.IO.BinaryWriter.Create(MyFileStream);

  // Write to the file
  MyFileWriter.Write('A');
  MyFileWriter.Write('BCD');
  MyFileWriter.Write(175);

  // Close the writer and the stream
  MyFileWriter.Close;
  MyFileStream.Close;

  // Reopen the stream for reading
  MyFileStream := System.IO.File.Open('C:DelphiBasics.txt',
                                      System.IO.FileMode.Open);

  // Create a BinaryReader to allow the file to be read back
  MyFileReader := System.IO.BinaryReader.Create(MyFileStream);

  // Display the file contents
  // Note : We must look for the 'EndOfStreamException'
  //        when using ReadByte to know when we are done
  try
    while 1 <> 0 do
    begin
      CharAsByte := MyFileReader.ReadByte;
      Console.WriteLine('{0:X}', TObject(CharAsByte));
    end;
  except
    On E : EndOfStreamException do
      Console.WriteLine('End of file encountered');
  end;

  // Close the reader and the stream
  MyFileReader.Close;
  MyFileStream.Close;

  Console.Readline;
end.
   41
   3
   42
   43
   44
   AF
   End of file encountered
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author