Hi Fpc-Pascal Users,
P.S. Although these classes are meant for compatibility with
Delphi/Windows,
that's not even entirely compatible. Afair Windows could partially
overwrite lines in the file instead of the whole file at once
maybe they should provide extra methods with correct exception
handling and "atomic" saving with temporary file?
I suggested that almost ten years ago but they didn’t want to:
https://gitlab.com/freepascal.org/fpc/source/-/issues/30439
Here everyone keeps running into the same problems year after year and
nothing improves
Or maybe someone can recommend alternatives?
I once overwrote UpdateFile to use temporary files:
https://github.com/benibela/videlibri/blob/master/inifilessafe.pas
Sincerely,
Benito
On 02.08.25 06:27, Flávio Etrusco via fpc-pascal wrote:
Em sex., 1 de ago. de 2025, 17:54, James Richters via fpc-pascal
<fpc-pascal@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?
_______________________________________________
fpc-pascal maillist -fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal