<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body smarttemplateinserted="true">
    <div id="smartTemplate4-template">Hi Fpc-Pascal Users,<br>
      <br>
      <blockquote type="cite">
        <div dir="auto"><br>
        </div>
        <div dir="auto">P.S. Although these classes are meant for
          compatibility with Delphi/Windows, </div>
      </blockquote>
      <br>
    </div>
    <div><br>
    </div>
    <div>that's not even entirely compatible. Afair Windows could
      partially overwrite lines in the file instead of the whole file at
      once<br>
    </div>
    <div><br>
    </div>
    <div><br>
      <blockquote type="cite">
        <div dir="auto">maybe they should provide extra methods with
          correct exception handling and "atomic" saving with temporary
          file?</div>
        <div dir="auto"><br>
        </div>
      </blockquote>
      <br>
    </div>
    <div><br>
      I suggested that almost ten years ago but they didn’t want to:<br>
      <p><a class="moz-txt-link-freetext"
href="https://gitlab.com/freepascal.org/fpc/source/-/issues/30439">https://gitlab.com/freepascal.org/fpc/source/-/issues/30439</a></p>
      Here everyone keeps running into the same problems year after year
      and nothing improves<br>
    </div>
    <div><br>
    </div>
    <div><br>
    </div>
    <div><br>
    </div>
    <div>
      <blockquote type="cite">Or maybe someone can recommend
        alternatives?</blockquote>
    </div>
    <div><br>
    </div>
    <div>I once overwrote UpdateFile to use temporary files:<br>
    </div>
    <div><br>
    </div>
    <div><a class="moz-txt-link-freetext"
href="https://github.com/benibela/videlibri/blob/master/inifilessafe.pas">https://github.com/benibela/videlibri/blob/master/inifilessafe.pas</a><br>
      <br>
    </div>
    <div><br>
      Sincerely,<br>
      Benito <br>
      <br>
    </div>
    <div class="moz-cite-prefix">On 02.08.25 06:27, Flávio Etrusco via
      fpc-pascal wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAJvBmOYK=m=d_19POP9GPxud6wc8ja44RHHJtzTuXZx_Uw4Dzw@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="auto">
        <div><br>
          <br>
          <div class="gmail_quote">
            <div dir="ltr" class="gmail_attr">Em sex., 1 de ago. de
              2025, 17:54, James Richters via fpc-pascal <<a
                href="mailto:fpc-pascal@lists.freepascal.org"
rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer"
                target="_blank" moz-do-not-send="true"
                class="moz-txt-link-freetext">fpc-pascal@lists.freepascal.org</a>>
              escreveu:<br>
            </div>
            <blockquote class="gmail_quote"
style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
              <div lang="EN-US" link="blue" vlink="purple">
                <div>
                  <p class="MsoNormal"><span
style="font-size:11pt;font-family:Calibri,sans-serif">Thank you for the
                      great suggestions!<span>  </span>I did not know I
                      could have a memory version of the <span>ini</span>
                      file. <br>
                      that sounds like a better solution than what I am
                      doing.<span>  </span>Right now I am reading in
                      all the <span>ini</span> settings and putting
                      them into variables like <br>
                      <span>Ini_myvariable</span><br>
                      <br>
                      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 <span>ini</span>
                      file directly?<br>
                      <br>
                      It seems like that would be much easier and also
                      solve the issues.<br>
                      <br>
                      James</span></p>
                </div>
              </div>
            </blockquote>
          </div>
        </div>
        <div dir="auto"><br>
        </div>
        <div dir="auto"><a
href="https://github.com/fpc/FPCSource/blob/main/packages/fcl-base/src/inifiles.pp"
rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer"
            target="_blank" moz-do-not-send="true"
            class="moz-txt-link-freetext">https://github.com/fpc/FPCSource/blob/main/packages/fcl-base/src/inifiles.pp</a></div>
        <div dir="auto"><br>
        </div>
        <div dir="auto">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.</div>
        <div dir="auto"><br>
        </div>
        <div dir="auto">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.</div>
        <div dir="auto"><br>
        </div>
        <div dir="auto">Regards,</div>
        <div dir="auto">Flávio </div>
        <div dir="auto"><br>
        </div>
        <div dir="auto">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?</div>
        <div dir="auto">Or maybe someone can recommend alternatives?</div>
        <div dir="auto">
          <div class="gmail_quote">
            <blockquote class="gmail_quote"
style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
            </blockquote>
          </div>
        </div>
      </div>
      <br>
      <fieldset class="moz-mime-attachment-header"></fieldset>
      <pre wrap="" class="moz-quote-pre">_______________________________________________
fpc-pascal maillist  -  <a
      class="moz-txt-link-abbreviated moz-txt-link-freetext"
      href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a>
<a class="moz-txt-link-freetext"
href="https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal">https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal</a>
</pre>
    </blockquote>
  </body>
</html>