Home  |  Delphi .net Home  |  System.IO.MemoryStream  |  ReadByte Method
ReadByte  
Method  
Returns the next byte from the current position inthe Memory Stream
MemoryStream Class
System.IO NameSpace
CF1.  Function ReadByte ( ) : Integer;
CF : Methods with this mark are Compact Framework Compatible
Description
The byte at the current position in the current Memory Stream is returned as an Integer. If the stream was already exhausted, then -1 is returned.
Microsoft MSDN Links
System.IO
System.IO.MemoryStream
 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

uses
  System.IO;

var
  Memory        : System.IO.MemoryStream;
  ByteAsInteger : Integer;

begin
  // Create our Memory Stream Writer
  Memory := System.IO.MemoryStream.Create;

  // Write to the stream
  Memory.WriteByte(1);
  Memory.WriteByte(2);
  Memory.WriteByte(3);

  // Position at the start of the stream
  Memory.Seek(0, SeekOrigin.Begin);

  // Now display the stream contents
  ByteAsInteger := Memory.ReadByte;

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

  // Close the stream
  Memory.Close;

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