[fpc-devel] FpFlock with Text as argument

Michael Van Canneyt michael at freepascal.org
Thu May 8 10:07:32 CEST 2008

On Wed, 7 May 2008, amir wrote:

> Hi,
> I don't know if it is a bug or I am using fpflock incorrectly. I wanted to use
> fpflock to lock a file (and be sure that only one process at a time can have
> access to my file).
> At first, I tried AssignFile and passed the TextFile(Text) variable to fpflock
> with LOCK_EX. It didn't work and both processes can access the file.
> Both print "After Flock".

After AssignFile(), there is no filehandle yet, so you cannot lock the
file. You can only lock the file after Reset() or ReWrite() was called.

Note that Reset and Rewrite will always work (unless the file doesn't exist,
obviously) even if another process has locked the file. The subsequent 
fplock() operation should determine whether another process has locked 
the file.


More information about the fpc-devel mailing list