[fpc-pascal] TIniFile crash
Flávio Etrusco
flavio.etrusco at gmail.com
Sat Aug 2 06:27:32 CEST 2025
Em sex., 1 de ago. de 2025, 17:54, James Richters via fpc-pascal <
fpc-pascal at lists.freepascal.org> escreveu:
> Thank you for the great suggestions! I did not know I could have a
> memory version of the ini file.
> that sounds like a better solution than what I am doing. Right now I am
> reading in all the ini settings and putting them into variables like
> Ini_myvariable
>
> then I use those as needed.. then write them all out, but if I am
> understanding it correctly could I just use the memory version of the ini
> file directly?
>
> It seems like that would be much easier and also solve the issues.
>
> James
>
https://github.com/fpc/FPCSource/blob/main/packages/fcl-base/src/inifiles.pp
To try to resolve your issue you should use TMemIniFile and invoke Rename()
before freeing the TMemIniFile (or invoking UpdateFile explicitly) to save
to the temporary file.
TMemIniFile is just TIniFile with some extra methods and with CacheUpdates
defaulting to True. They parse the whole ini file in the constructor, so
values are always read from memory.
Regards,
Flávio
P.S. Although these classes are meant for compatibility with
Delphi/Windows, maybe they should provide extra methods with correct
exception handling and "atomic" saving with temporary file?
Or maybe someone can recommend alternatives?
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20250802/6c61482e/attachment.htm>
More information about the fpc-pascal
mailing list