Home  |  Delphi .net Home  |  System.IO.MemoryStream  |  Write Method
Write  
Method  
Write some or all of an Array of Bytes into the current memory Stream
MemoryStream Class
System.IO NameSpace
CF1.  Procedure Write ( Bytes:Array of ByteBytes : Array of Byte; StartIndex : Integer; Count : Integer; ) ;
CF : Methods with this mark are Compact Framework Compatible
Description
Count bytes are copied from StartIndex of the Bytes array to the current position of the Memory Stream. The position is updated accordingly.
Microsoft MSDN Links
System.IO
System.IO.MemoryStream
 
 
Writing the middle of a Byte array to the current Memory Stream
program Project1;
{$APPTYPE CONSOLE}

uses
  System.IO;

var
  Memory        : System.IO.MemoryStream;
  ByteArray     : Array of Byte;
  ByteAsInteger : Integer;

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

  // Set the array length
  SetLength(ByteArray, 10);

  // Write to the array
  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;

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

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