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

Rafael Picanço via fpc-pascal <[email protected]>
Newsgroups gmane.comp.compilers.free-pascal.general
Message-ID <CAGpuCi6zMDeVukU5ezb-0rqUTgwY-zhdPFge-FNFmwzju+EUNQ@mail.gmail.com>
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

On Sat, Aug 2, 2025 at 7:09 AM <[email protected]>
wrote:

> Send fpc-pascal mailing list submissions to
>         [email protected]
>
> 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
>         fpc-pascal-request-PD4FTy7X32k2wBtHl531yWD2FQJk+8+b@public.gmane.org
>
> You can reach the person managing the list at
>         fpc-pascal-owner-PD4FTy7X32k2wBtHl531yWD2FQJk+8+b@public.gmane.org
>
> 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 <[email protected]>
> To: FPC-Pascal users discussions <[email protected]>
> Subject: Re: [fpc-pascal] TIniFile crash
> Message-ID:
>         <CAGpuCi7Yh=
> CtgA8fPmKx28v8qttWMiqj1jHgA7H9otyrZg72Fw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
> 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 <[email protected]>
> To: [email protected],  FPC-Pascal users discussions
>         <[email protected]>
> Cc: James Richters <[email protected]>
> Subject: Re: [fpc-pascal] TIniFile crash
> Message-ID:
>         <CAJvBmOYK=m=
> d_19POP9GPxud6wc8ja44RHHJtzTuXZx_Uw4Dzw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
> Content-Type: text/plain; charset="utf-8"
>
> Em sex., 1 de ago. de 2025, 17:54, James Richters via fpc-pascal <
> [email protected]> 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  -  [email protected]
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
>
>
> ------------------------------
>
> End of fpc-pascal Digest, Vol 254, Issue 3
> ******************************************
>

_______________________________________________
fpc-pascal maillist  -  [email protected]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.