Home  |  Delphi .net Home  |  System.IO.BufferedStream  |  Seek Method
Seek  
Method  
Moves the current position in the buffered stream to the specified value
BufferedStream Class
System.IO NameSpace
NotCF1.  Procedure Seek ( Offset:Int64Offset : Int64; Origin : System.IO.SeekOrigin; ) ;
CF : Methods with this mark are Compact Framework Compatible
Description
A buffered 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.BufferedStream
 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

uses
  System.IO;

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

  // Write to the memory stream using the BufferedStream
  Stream.WriteByte(1);
  Stream.WriteByte(2);
  Stream.WriteByte(3);
  Stream.WriteByte(4);
  Stream.WriteByte(5);

  // Now seek to index 2 in the stream
  Stream.Seek(2, 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
  3
  4
  5
 
 
Delphi Programming © Neil Moffatt All rights reserved.  |  Contact the author