[fpc-pascal] Detecting IO errors with INI file

James Richters james.richters at productionautomation.net
Thu Apr 29 03:13:40 CEST 2021


I'm trying to detect if an INI file is open by another program, but the way
I normally do this is not working.
 
// open the file for write and keep it open to test
Assign(myfile,'my.ini');
Rewrite(myfile);
   
{$i-}
Assign(myfile2, 'my.ini';
Rewrite(myfile2);    //try to open it for write again
Writeln(ioresult);    //correctly displays a 5 for access denied
{$i+}
 
 
{$i-}
Log_Ini := TIniFile.Create('my.ini');   // blows up with 217
Writeln(ioresult);
{$i+}
 
The error I get is:
An unhandled exception occurred at $005A57D0:
EFOpenError: Unable to open file "LOG.INI": The process cannot access the
file because it is being used by another process.
 
I want to just keep trying to open it until the other process is done.  I
don't understand why it's an 'unhandled exception' when I was handling it.
I guess TiniFile.Create has an {$i+} in it and so that's why it's blowing
up?
 
Any ideas how to keep retrying to access with ini file until it is either
successful or a timeout?
 
James
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20210428/d35d1e72/attachment-0001.htm>


More information about the fpc-pascal mailing list