<div dir="ltr"><div dir="ltr"><br></div>Hi James, here are some routines to a load-create/archive cycle using a temporary TIniFile:<div><br></div><div>program handle_inifile;<br><br>uses Classes, SysUtils, IniFiles,</div><div>FileUtil;// In Lazarus you will need the LazUtils package to see the FileUtil unit<br><br>procedure ArchiveIniFileTo(var AIniFile : TIniFile; ADestination : string);<br>begin<br>  if Assigned(AIniFile) then begin<br>    { You may want to implement a method<br>      to update/invalidate in-memory stuff here }<br>    //IniFileDescendent.Invalidate;<br>    AIniFile.UpdateFile; // Flush data to disc<br><br>    CopyFile(AIniFile.FileName, ADestination);<br>    if FileExists(AIniFile.FileName) then begin<br>      DeleteFile(AIniFile.FileName);<br>    end;<br>  end;<br>end;<br><br>function LoadIniFile(AFilename: string) : TIniFile;<br>begin<br>  Result := TIniFile.Create(AFilename);<br>  Result.CacheUpdates := True;<br>end;<br><br>var<br>  TemporaryIniFile : TIniFile;<br><br>begin<br>  TemporaryIniFile := LoadIniFile('tmp.ini');</div><div>  try<br>    TemporaryIniFile.WriteString('Section', 'Key', 'Value'); // in memory cached updates<br>     ArchiveIniFileTo(TemporaryIniFile, 'destination.ini');</div><div>  finally</div><div>    
TemporaryIniFile 

.Free;  </div><div>  end;<br>end. </div><div><div><br></div><div>I use this approach because in-memory manipulation of the ini file is what I need (with the bonus of being faster and safer).</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 Thu, Jul 31, 2025 at 10:39 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 (Michael Van Canneyt)<br>
   2.  Broken Links on Free Pascal Wiki (Tim Coates)<br>
<br>
<br>
----------------------------------------------------------------------<br>
<br>
Message: 1<br>
Date: Wed, 30 Jul 2025 16:25:51 +0200 (CEST)<br>
From: Michael Van Canneyt <<a href="mailto:michael@freepascal.org" target="_blank">michael@freepascal.org</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: <<a href="mailto:1c5e79f3-5698-690b-b7be-7900484ba51c@freepascal.org" target="_blank">1c5e79f3-5698-690b-b7be-7900484ba51c@freepascal.org</a>><br>
Content-Type: text/plain; charset="utf-8"; Format="flowed"<br>
<br>
<br>
<br>
On Tue, 29 Jul 2025, James Richters via fpc-pascal wrote:<br>
<br>
> I will try just creating a temp file, and once it?s completed delete the original file then rename the temp file to the correct name, it?s a good idea, and a least I will now that nothing I am doing is trying to access the file? because I can generate some random name for the temp file,  but I guess it wouldn?t stop something like antivirus from trying to scan it before I?m done.   It?s a difficult problem to figure out because it happens very rarely, but it does happen enough to be annoying.<br>
><br>
> I put the delete and wait for it to be gone procedure just to make sure the file was really gone before trying to create a new one in an attempt to solve this issue, and it is well past that part of the code when the crash happens, it had already written 19 entries to the new  ini file when it crashed, and that?s why I?m confused, the error is about creating the file, but it was already created and there were already 19 successful entries to it? so what?s it creating at the point of the crash?<br>
><br>
> The thing is that the file that is on the disk after the crash is only a partial file, up to the exact line that crashed, so the file must have finished the delete and there was no problem creating a new file and writing to it.<br>
><br>
> I am having a suspicion that Ini.WriteString is opening the file, writing to it then closing it, which makes no sense to me, I would think that ini.create would create the file and open it, and it would remain open until ini.free..  but the fact that it sometimes gives me this message:<br>
><br>
> EFCreateError: Unable to create file "I:\Programming\Gcode\Mill\Location.ini": The process cannot access the file because it is being used by another process.<br>
>  $00603277<br>
><br>
> After writing successfully 19 entries to the ini files seems to indicate<br>
> that it?s opening and closing the file for each Ini.WriteString and that<br>
> 1% of the time the OS didn?t finish writing the file before it was being<br>
> opened again?  I?m just guessing here about what could cause this.<br>
<br>
The TIniFile indeed writes to disk after every writeNNN()<br>
<br>
There are 2 possibilities to change this behaviour:<br>
<br>
- Set CacheUpdates to true, and call UpdateFile when done.<br>
<br>
- Use TMemInifile, and call UpdateFile when done.<br>
   (TMemIniFIle simply sets CacheUpdates to true in its constructor)<br>
<br>
This should improve matters.<br>
<br>
You can also combine this with the "use temp filename and rename" approach.<br>
<br>
Michael.<br>
<br>
------------------------------<br>
<br>
Message: 2<br>
Date: Thu, 31 Jul 2025 17:50:57 +1000<br>
From: Tim Coates <<a href="mailto:timcoates.solutions@gmail.com" target="_blank">timcoates.solutions@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: [fpc-pascal] Broken Links on Free Pascal Wiki<br>
Message-ID:<br>
        <<a href="mailto:CAPGcr8-zO1-SEeSiNxXXTeO5HcwsY%2By1ndq%2BvKdAq3Lj0RRVuA@mail.gmail.com" target="_blank">CAPGcr8-zO1-SEeSiNxXXTeO5HcwsY+y1ndq+vKdAq3Lj0RRVuA@mail.gmail.com</a>><br>
Content-Type: text/plain; charset="utf-8"<br>
<br>
Dear Free Pascal Team,<br>
<br>
I understand and appreciate that Free Pascal is a volunteer-driven project,<br>
and I?m grateful for all the work that has gone into it over the years.<br>
<br>
While researching style guides for something I?m working on, I went to the<br>
Free Pascal wiki to look for documentation. Unfortunately, both the links I<br>
found for the style guide and the project guidelines appear to be dead. I<br>
was hoping to refer to these resources, but couldn?t access them. I could<br>
otherwise Delphi 11 based guide?<br>
<br>
Out of curiosity, I also wondered whether there might be other important<br>
pages that have gone offline or been moved. Is there an updated location<br>
for these documents? And if there?s a way I could help with checking or<br>
updating wiki links, I?d be happy to pitch in.<br>
<br>
Thanks again for your time and for maintaining such a valuable tool for the<br>
Pascal community.<br>
<br>
Best regards,<br>
Tim Coates<br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <<a href="http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20250731/1a5bb934/attachment-0001.htm" rel="noreferrer" target="_blank">http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20250731/1a5bb934/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 253, Issue 16<br>
*******************************************<br><br>
</blockquote></div></div></div></div>