<div dir="ltr"><div>Flavio, thanks for that! </div><div><br></div><div>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:</div><div><br></div>procedure ArchiveIniFileTo(AMemIniFile: TMemIniFile; ADestination : string);<div>var</div><div>  TemporaryDestination : string;</div><div>begin</div><div>    TemporaryDestination := 



AMemIniFile.Filename;</div><div>    

AMemIniFile.RenameAndNothingElse(ADestination);</div><div>    

AMemIniFile.UpdateFile; // Flush data to disc<br>    AMemIniFile.RenameAndNothingElse(TemporaryDestination);</div><div>end;</div><div><br></div><div>Best,</div><div>Rafael Picanço</div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Sat, Aug 2, 2025 at 7:09 AM <<a href="mailto:fpc-pascal-request@lists.freepascal.org">fpc-pascal-request@lists.freepascal.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Send fpc-pascal mailing list submissions to<br>
        <a href="mailto:fpc-pascal@lists.freepascal.org" target="_blank">fpc-pascal@lists.freepascal.org</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
        <a href="https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal" rel="noreferrer" target="_blank">https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal</a><br>
or, via email, send a message with subject or body 'help' to<br>
        <a href="mailto:fpc-pascal-request@lists.freepascal.org" target="_blank">fpc-pascal-request@lists.freepascal.org</a><br>
<br>
You can reach the person managing the list at<br>
        <a href="mailto:fpc-pascal-owner@lists.freepascal.org" target="_blank">fpc-pascal-owner@lists.freepascal.org</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than "Re: Contents of fpc-pascal digest..."<br>
<br>
<br>
Today's Topics:<br>
<br>
   1. Re:  TIniFile crash (Rafael Pican?o)<br>
   2. Re:  TIniFile crash (Fl?vio Etrusco)<br>
<br>
<br>
----------------------------------------------------------------------<br>
<br>
Message: 1<br>
Date: Fri, 1 Aug 2025 23:53:10 -0300<br>
From: Rafael Pican?o <<a href="mailto:cpicanco42@gmail.com" target="_blank">cpicanco42@gmail.com</a>><br>
To: FPC-Pascal users discussions <<a href="mailto:fpc-pascal@lists.freepascal.org" target="_blank">fpc-pascal@lists.freepascal.org</a>><br>
Subject: Re: [fpc-pascal] TIniFile crash<br>
Message-ID:<br>
        <CAGpuCi7Yh=<a href="mailto:CtgA8fPmKx28v8qttWMiqj1jHgA7H9otyrZg72Fw@mail.gmail.com" target="_blank">CtgA8fPmKx28v8qttWMiqj1jHgA7H9otyrZg72Fw@mail.gmail.com</a>><br>
Content-Type: text/plain; charset="utf-8"<br>
<br>
>> then I use those as needed.. then write them all out, but if I am<br>
understanding it correctly could I just use the memory version of the ini<br>
file directly?<br>
<br>
In my case, I have a protocol where some parameters must be archived and<br>
IniFiles are handy when I need to do some eye inspection on them.<br>
Currently, I use IniFiles as in-memory to be archived and<br>
IniFile.ReadSectionValues('Section', TStringList(Instance)) for dynamic<br>
stuff.<br>
<br>
Best,<br>
Rafael Pican?o<br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <<a href="http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20250801/1bd47eda/attachment-0001.htm" rel="noreferrer" target="_blank">http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20250801/1bd47eda/attachment-0001.htm</a>><br>
<br>
------------------------------<br>
<br>
Message: 2<br>
Date: Sat, 2 Aug 2025 01:27:32 -0300<br>
From: Fl?vio Etrusco <<a href="mailto:flavio.etrusco@gmail.com" target="_blank">flavio.etrusco@gmail.com</a>><br>
To: <a href="mailto:james@productionautomation.net" target="_blank">james@productionautomation.net</a>,  FPC-Pascal users discussions<br>
        <<a href="mailto:fpc-pascal@lists.freepascal.org" target="_blank">fpc-pascal@lists.freepascal.org</a>><br>
Cc: James Richters <<a href="mailto:james.richters@productionautomation.net" target="_blank">james.richters@productionautomation.net</a>><br>
Subject: Re: [fpc-pascal] TIniFile crash<br>
Message-ID:<br>
        <CAJvBmOYK=m=<a href="mailto:d_19POP9GPxud6wc8ja44RHHJtzTuXZx_Uw4Dzw@mail.gmail.com" target="_blank">d_19POP9GPxud6wc8ja44RHHJtzTuXZx_Uw4Dzw@mail.gmail.com</a>><br>
Content-Type: text/plain; charset="utf-8"<br>
<br>
Em sex., 1 de ago. de 2025, 17:54, James Richters via fpc-pascal <<br>
<a href="mailto:fpc-pascal@lists.freepascal.org" target="_blank">fpc-pascal@lists.freepascal.org</a>> escreveu:<br>
<br>
> Thank you for the great suggestions!  I did not know I could have a<br>
> memory version of the ini file.<br>
> that sounds like a better solution than what I am doing.  Right now I am<br>
> reading in all the ini settings and putting them into variables like<br>
> Ini_myvariable<br>
><br>
> then I use those as needed.. then write them all out, but if I am<br>
> understanding it correctly could I just use the memory version of the ini<br>
> file directly?<br>
><br>
> It seems like that would be much easier and also solve the issues.<br>
><br>
> James<br>
><br>
<br>
<a href="https://github.com/fpc/FPCSource/blob/main/packages/fcl-base/src/inifiles.pp" rel="noreferrer" target="_blank">https://github.com/fpc/FPCSource/blob/main/packages/fcl-base/src/inifiles.pp</a><br>
<br>
To try to resolve your issue you should use TMemIniFile and invoke Rename()<br>
before freeing the TMemIniFile (or invoking UpdateFile explicitly) to save<br>
to the temporary file.<br>
<br>
TMemIniFile is just TIniFile with some extra methods and with CacheUpdates<br>
defaulting to True. They parse the whole ini file in the constructor, so<br>
values are always read from memory.<br>
<br>
Regards,<br>
Fl?vio<br>
<br>
P.S. Although these classes are meant for compatibility with<br>
Delphi/Windows, maybe they should provide extra methods with correct<br>
exception handling and "atomic" saving with temporary file?<br>
Or maybe someone can recommend alternatives?<br>
<br>
><br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <<a href="http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20250802/6c61482e/attachment-0001.htm" rel="noreferrer" target="_blank">http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20250802/6c61482e/attachment-0001.htm</a>><br>
<br>
------------------------------<br>
<br>
Subject: Digest Footer<br>
<br>
_______________________________________________<br>
fpc-pascal maillist  -  <a href="mailto:fpc-pascal@lists.freepascal.org" target="_blank">fpc-pascal@lists.freepascal.org</a><br>
<a href="https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal" rel="noreferrer" target="_blank">https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal</a><br>
<br>
<br>
------------------------------<br>
<br>
End of fpc-pascal Digest, Vol 254, Issue 3<br>
******************************************<br>
</blockquote></div>