[fpc-pascal] Detecting IO errors with INI file

Sven Barth pascaldragon at googlemail.com
Thu Apr 29 07:46:35 CEST 2021


James Richters via fpc-pascal <fpc-pascal at lists.freepascal.org> schrieb am
Do., 29. Apr. 2021, 03:13:

> {$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
>
TIniFile does not make use of IOResult, because it's from the Delphi time,
not the TP time. Thus you need to use Object Pascal exception handling:

=== code begin ===

try
  Log_ini := TIniFile.Create('myini.ini');
except
  on e: EFOpenError do
    // handle this to decide whether to retry
  on e: Exception do
    // handle other problems
end;

=== code end ===

Regards,
Sven

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20210429/4e7d8e0f/attachment.htm>


More information about the fpc-pascal mailing list