Home  |  Delphi .net Home  |  System.IO.FileStream  |  UnLock Method
  
UnLock  
Method  
UnLock a section of the current stream, allowing others to write to it
FileStream Class
System.IO NameSpace
NotCF1.  Procedure UnLock ( StartIndex : Int64; Count : Int64 ) ;
CF : Methods with this mark are Compact Framework Compatible
Description
Count bytes from StartIndex are unlocked. This now allows other, concurrent processes writing to them.
Notes
This is somewhat beyond Delphi Basics, so the example merely illustrates the syntax.
Microsoft MSDN Links
System.IO
System.IO.FileStream
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 
 
Illustrating the syntax
program Project1;
{$APPTYPE CONSOLE}

uses
  System.IO;

var
  Stream : System.IO.FileStream;
  i      : 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'
  Stream.WriteByte(68);  // Chr(68) = 'D'
  Stream.WriteByte(69);  // Chr(69) = 'E'

  // Lock the last 3 bytes for update
  Stream.Lock(2, 3);

  // Now any concurrent process will be unable to write to
  // these last 3 bytes of the file.

  // ... Run a concurrent process at this point

  // Unlock the file
  Stream.UnLock(2, 3);

  // Close the stream
  Stream.Close;

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