Home  |  Delphi .net Home  |  System.IO.MemoryStream  |  SetLength Method
SetLength  
Method  
Sets the length of the memory stream
MemoryStream Class
System.IO NameSpace
CF1.  Procedure SetLength ( Length : Int64; ) ;
CF : Methods with this mark are Compact Framework Compatible
Description
The current Memory Stream size is changed to Length bytes. If this shortens the stream, bytes are lost at the end, otherwise bytes with 0 value are added to the end.
Microsoft MSDN Links
System.IO
System.IO.MemoryStream
 
 
Extending a 3 byte stream to 10 bytes
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 make the Memory stream longer
  Memory.SetLength(10);

  // 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
  0
  0
  0
  0
  0
  0
  0
 
 
Delphi Programming © Neil Moffatt All rights reserved.  |  Contact the author