There are two different ways in window to lock files or parts of files.
1.) file locking
While a file is opened it is protected against deleting.
Windows doesn't allow to delete a file while it is opened by one or more processes.
2.) record locking
With LockFile() and UnlockFile() you can lock a range of bytes to prevent an other process to read or write this part of the file.
Delphi-Quellcode:
var
fs : TFileStream;
s : Ansistring;
begin
fs := TFileStream.Create(filename, fmOpenRead
or fmShareDenyWrite);
try
// File is open now and can't be deleted
...
// read some data from file
SetLength(s, 100);
fs.ReadBuffer(s[1], 100);
....
finally
fs.free;
// close file handle and free memory for FileStream object
end;
end;