Home  |  Delphi .net Home  |  System.IO.MemoryStream  |  WriteTo Method
WriteTo  
Method  
Writes the complete current Memory Stream to another stream
MemoryStream Class
System.IO NameSpace
CF1.  Function WriteTo ( TargetStream ) : Stream;
CF : Methods with this mark are Compact Framework Compatible
Description
All bytes in the current memory Stream are written to the TargetStream. This can be any stream that inherits from Syystem.IO.Stream
Microsoft MSDN Links
System.IO
System.IO.MemoryStream
 
 
Copying from one Memory Stream to another
program Project1;
{$APPTYPE CONSOLE}

uses
  System.IO;

var
  Memory1, Memory2 : System.IO.MemoryStream;
  ByteAsInteger    : Integer;

begin
  // Create our Memory Stream Writers
  Memory1 := System.IO.MemoryStream.Create;
  Memory2 := System.IO.MemoryStream.Create;

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

  // Write the contents to a second memory stream
  Memory1.WriteTo(Memory2);

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

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

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

  // Close the streams
  Memory1.Close;
  Memory2.Close;

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