Home  |  Delphi .net Home  |  System.IO.BufferedStream  |  ReadByte Method
ReadByte  
Method  
Read the next Byte from the current stream
BufferedStream Class
System.IO NameSpace
NotCF1.  Function ReadByte ( ) : Integer;
CF : Methods with this mark are Compact Framework Compatible
Description
The next Byte is read from the stream at the current position, and the position incremented accordingly. If the stream was exhasuted before the read, then -1 is returned.
Microsoft MSDN Links
System.IO
System.IO.BufferedStream
 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

uses
  System.IO;

var
  Memory    : System.IO.MemoryStream;
  Stream    : System.IO.BufferedStream;
  ByteAsInt : Integer;

begin
  // Create our memory stream
  Memory := System.IO.MemoryStream.Create;

  // Create out BufferedStream to access this memory stream
  Stream := System.IO.BufferedStream.Create(Memory);

  // Write to the memory stream using the BufferedStream
  Stream.WriteByte(1);
  Stream.WriteByte(2);
  Stream.WriteByte(3);

  // Now seek to the start of the stream
  Stream.Seek(0, SeekOrigin.Begin);

  // Now display the contents
  ByteAsInt := Stream.ReadByte;

  while ByteAsInt > 0 do
  begin
    Console.WriteLine(ByteAsInt.ToString);
    ByteAsInt := Stream.ReadByte;
  end;

  // Close the stream
  Stream.Close;

  Console.Readline;
end.
Show full unit code
  1
  2
  3
 
 
Delphi Programming © Neil Moffatt All rights reserved.  |  Contact the author