Re: [fpc-pascal] Detecting IO errors with INI file
Thanks everyone for the help. I have it working now I did some more searching and found out I can get "Try" to work with {$Mode TP} If I add {$Modeswitch exceptions} and appearantly {$R+} to make sure range checking is on. So I have it working in my {$Mode TP} Unit. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Detecting IO errors with INI file
On Thu, 29 Apr 2021, James Richters via fpc-pascal wrote: Best add SysUtils and Classes. Thanks, that worked. But now I'm getting "cannot read or write variables of this type" for Writeln(Exception) is there an easy way to find out what the exception is? On E : Exception do Writeln(E.ClassName,' : ',E.Message); Adapt E to whatever variable you used. Michael. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Detecting IO errors with INI file
>Best add SysUtils and Classes. Thanks, that worked. But now I'm getting "cannot read or write variables of this type" for Writeln(Exception) is there an easy way to find out what the exception is? James ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Detecting IO errors with INI file
On Thu, 29 Apr 2021, James Richters via fpc-pascal wrote: I’m trying to put the Ini file stuff all in it’s own unit. My unit is {$Mode OBJFPC} and Uses IniFiles; “Try” is compiling, but I’m getting Error: Identifier not found “EFOpenError” And also Syntax error “Do” expected but “)” found I have: try Log_ini := TIniFile.Create('myini.ini'); except on e: EFOpenError do // Identifier not found “EFOPenError” Writeln(EFOpenError); on e: Exception do Writeln(Exception); end; Do I need some other unit for EFOpenError to work? Best add SysUtils and Classes. Michael.___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Detecting IO errors with INI file
I’m trying to put the Ini file stuff all in it’s own unit. My unit is {$Mode OBJFPC} and Uses IniFiles; “Try” is compiling, but I’m getting Error: Identifier not found “EFOpenError” And also Syntax error “Do” expected but “)” found I have: try Log_ini := TIniFile.Create('myini.ini'); except on e: EFOpenError do // Identifier not found “EFOPenError” Writeln(EFOpenError); on e: Exception do Writeln(Exception); end; Do I need some other unit for EFOpenError to work? James ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Detecting IO errors with INI file
James Richters schrieb am Do., 29. Apr. 2021, 10:33: > I get Error: Identifier not found “Try” > > Because my unit must be compiled with {$MODE TP} > You can try to use {$modeswitch exceptions}, I think. Otherwise quite a few procedures and functions won’t even compile that only > work in Turbo Pascal mode. > > > > I guess I can put it in another unit and make a call to that… then I can > use Try > Considering that you're using Object Pascal functionality with TIniFile it might be best to put that into a separate unit. Regards, Sven ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Detecting IO errors with INI file
I get Error: Identifier not found “Try” Because my unit must be compiled with {$MODE TP} Otherwise quite a few procedures and functions won’t even compile that only work in Turbo Pascal mode. I guess I can put it in another unit and make a call to that… then I can use Try Thanks for the information. James ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Detecting IO errors with INI file
James Richters via fpc-pascal 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 > ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Detecting IO errors with INI file
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 ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal