Home  |  Delphi .net Home  |  System.IO.MemoryStream  |  Seek Method
  
Seek  
Method  
Moves the current position in the Memory Stream to the specified value
MemoryStream Class
System.IO NameSpace
CF1.  Procedure Seek ( Offset : Int64; Origin : System.IO.SeekOrigin ) ;
CF : Methods with this mark are Compact Framework Compatible
Description
A memory stream supports direct access to sections of the stream. You might, for example, want to treat the stream as a set of records, and then Seek to a certain record in order to update the values.
 
You can seek to a specified byte Offset from one of the following Origin values :
 
SeekOrigin.Begin Byte 0 of the stream
SeekOrigin.Current The current stream position
SeekOrigin.End After the final byte of the stream
References
SeekOrigin
Microsoft MSDN Links
System.IO
System.IO.MemoryStream
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 
 
Gettting the first and last bytes of a Memory Stream
program Project1;
{$APPTYPE CONSOLE}

uses
  System.IO;

var
  Memory    : System.IO.MemoryStream;

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

  // Write to the stream
  Memory.WriteByte(1);
  Memory.WriteByte(2);
  Memory.WriteByte(3);
  Memory.WriteByte(4);
  Memory.WriteByte(5);
  Memory.WriteByte(6);
  Memory.WriteByte(7);
  Memory.WriteByte(8);
  Memory.WriteByte(9);

  // Move to the start of the stream
  Memory.Seek(0, SeekOrigin.Begin);

  // Display the byte at this position
  Console.WriteLine('At offset 0 from the Beginning : {0}',
                    Memory.ReadByte.ToString);

  // Move to the byte at the end of the stream
  Memory.Seek(-1, SeekOrigin.End);

  // Display the byte at this position
  Console.WriteLine('At offset -1 from the End      : {0}',
                    Memory.ReadByte.ToString);

  // Close the memory stream
  Memory.Close;

  Console.Readline;
end.
   At offset 0 from the Beginning : 1
   At offset -1 from the End      : 9
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author