Home  |  Delphi .net Home  |  System.IO.BufferedStream  |  Write Method
Write  
Method  
Writes some or all bytes from a Byte Array into the current stream
BufferedStream Class
System.IO NameSpace
NotCF1.  Procedure Write ( Bytes:Array of ByteBytes : Array of Byte; ArrayOffset : Integer; Count : Integer; ) ;
CF : Methods with this mark are Compact Framework Compatible
Description
Up to Count bytes are copied from ArrayOffset in the Bytes array to the current position in the stream.
Notes
An exception is raised if the bounds of the Bytes array are exceeded.
Microsoft MSDN Links
System.IO
System.IO.BufferedStream
 
 
Writing the middle of a Byte array to the current stream
program Project1;
{$APPTYPE CONSOLE}

uses
  System.IO;

var
  Memory    : System.IO.MemoryStream;
  Stream    : System.IO.BufferedStream;
  ByteArray : Array of Byte;
  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);

  // Create our byte array
  SetLength(ByteArray, 10);

  // And fill it
  ByteArray[0] := 0;
  ByteArray[1] := 1;
  ByteArray[2] := 2;
  ByteArray[3] := 3;
  ByteArray[4] := 4;
  ByteArray[5] := 5;
  ByteArray[6] := 6;
  ByteArray[7] := 7;
  ByteArray[8] := 8;
  ByteArray[9] := 9;

  // Now write the middle of the array to the stream
  Stream.Write(ByteArray, 2, 5);

  // 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
  2
  3
  4
  5
  6
 
 
Delphi Programming © Neil Moffatt All rights reserved.  |  Contact the author