[Lazarus] File is locked?

Mark Morgan Lloyd markMLl.lazarus at telemetry.co.uk
Sun Nov 15 09:28:29 CET 2015


Leonardo M. Ramé wrote:
> Hi, I'm checking the contents of an .ini file every 10 seconds (with a 
> TTimer), the file is modified by another application and I display its 
> contents in my program.
> 
> The problem is the file is locked while the other program is using it 
> and aparently TIniFile cannot handle this situation, thus raising an 
> "Unable to open file" error. How can I check if the file is locked 
> before reading its contents?.

I don't think you can, because it has to be an atomic operation. Also 
the locking behaviour varies a lot depending on operating system 
(whatever it is in your case ;-)

I think you'd do better monitoring the file timestamp(s) so that you're 
not reparsing it redundantly, and being prepared to handle cases where 
IniFile fails. You might be able to request change notifications, but 
again that depends heavily on OS.

-- 
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]




More information about the Lazarus mailing list