Home  |  Delphi .net Home  |  System.IO.FileStream  |  Seek Method
  
Seek  
Method  
Moves the current position in the current stream to the specified value
FileStream Class
System.IO NameSpace
CF1.  Procedure Seek ( Offset : 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.FileStream
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

uses
  System.IO;

var
  Stream        : System.IO.FileStream;
  ByteAsInteger : Integer;

begin
  // Open the file for writing
  Stream := System.IO.FileStream.Create('C:\DelphiBasics.txt',
                                        FileMode.Create);

  // Write to the file
  Stream.WriteByte(65);  // Chr(65) = 'A'
  Stream.WriteByte(66);  // Chr(66) = 'B'
  Stream.WriteByte(67);  // Chr(67) = 'C'

  // Move to the start of the file
  Stream.Seek(0, SeekOrigin.Begin);

  // Display the contents
  ByteAsInteger := Stream.ReadByte;
  while ByteAsInteger >= 0 do
  begin
    Console.Write(Char(ByteAsInteger));
    ByteAsInteger := Stream.ReadByte;
  end;

  // Close the stream
  Stream.Close;

  Console.Readline;
end.
   ABC
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author