Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2025-08

Re: fpc-pascal Digest, Vol 254, Issue 3

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Rafael Picanço

Flavio, thanks for that!

However, TMemIniFile.Rename cleans up its content with FStream := nil (Am I
correct?). So, In my case I would need to adapt it further so that:
procedure ArchiveIniFileTo(AMemIniFile: TMemIniFile; ADestination : string);
var
  TemporaryDestination : string;
begin
    TemporaryDestination :=  AMemIniFile.Filename;
    AMemIniFile.RenameAndNothingElse(ADestination);
    AMemIniFile.UpdateFile; // Flush data to disc
    AMemIniFile.RenameAndNothingElse(TemporaryDestination);
end;

Best,
Rafael Picanço

Show quoted text 123 lines
Send fpc-pascal mailing list submissions to To subscribe or unsubscribe via the World Wide Web, visit https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal or, via email, send a message with subject or body 'help' to You can reach the person managing the list at When replying, please edit your Subject line so it is more specific than "Re: Contents of fpc-pascal digest..." Today's Topics: 1. Re: TIniFile crash (Rafael Pican?o) 2. Re: TIniFile crash (Fl?vio Etrusco) ---------------------------------------------------------------------- Message: 1 Date: Fri, 1 Aug 2025 23:53:10 -0300 From: Rafael Pican?o To: FPC-Pascal users discussions Subject: Re: [fpc-pascal] TIniFile crash Message-ID: <CAGpuCi7Yh= > Content-Type: text/plain; charset="utf-8" >> 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? In my case, I have a protocol where some parameters must be archived and IniFiles are handy when I need to do some eye inspection on them. Currently, I use IniFiles as in-memory to be archived and IniFile.ReadSectionValues('Section', TStringList(Instance)) for dynamic stuff. Best, Rafael Pican?o -------------- next part -------------- An HTML attachment was scrubbed... URL: < http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20250801/1bd47eda/attachment-0001.htm > ------------------------------ Message: 2 Date: Sat, 2 Aug 2025 01:27:32 -0300 From: Fl?vio Etrusco To: , FPC-Pascal users discussions Cc: James Richters Subject: Re: [fpc-pascal] TIniFile crash Message-ID: <CAJvBmOYK=m= > Content-Type: text/plain; charset="utf-8" Em sex., 1 de ago. de 2025, 17:54, James Richters via fpc-pascal < > 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-0001.htm > ------------------------------ Subject: Digest Footer _______________________________________________ fpc-pascal maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal ------------------------------ End of fpc-pascal Digest, Vol 254, Issue 3 ******************************************
Flávio Etrusco
to Rafael Picanço

Em sáb., 2 de ago. de 2025 às 11:19, Rafael Picanço via fpc-pascal <

Show quoted text 21 lines
escreveu: Flavio, thanks for that! However, TMemIniFile.Rename cleans up its content with FStream := nil (Am I correct?). So, In my case I would need to adapt it further so that: procedure ArchiveIniFileTo(AMemIniFile: TMemIniFile; ADestination : string); var TemporaryDestination : string; begin TemporaryDestination := AMemIniFile.Filename; AMemIniFile.RenameAndNothingElse(ADestination); AMemIniFile.UpdateFile; // Flush data to disc AMemIniFile.RenameAndNothingElse(TemporaryDestination); end; Best, Rafael Picanço

No, Rename() doesn't cleanup the contents. FStream is only stored (if you load/initialize the TIniFile/TMemIniFile from a stream) so that UpdateFile() can update/overwrite that stream with the new ini values. When loading from a stream, TIniFile/TMemIniFile read all values inside its constructor, just like when loading from a file.

-Flávio