[fpc-pascal] fpc-pascal Digest, Vol 254, Issue 3
Rafael Picanço
cpicanco42 at gmail.com
Sat Aug 2 16:18:48 CEST 2025
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 <fpc-pascal-request at lists.freepascal.org>
wrote:
> Send fpc-pascal mailing list submissions to
> fpc-pascal at lists.freepascal.org
>
> 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 at lists.freepascal.org
>
> You can reach the person managing the list at
> fpc-pascal-owner at lists.freepascal.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 <cpicanco42 at gmail.com>
> To: FPC-Pascal users discussions <fpc-pascal at lists.freepascal.org>
> Subject: Re: [fpc-pascal] TIniFile crash
> Message-ID:
> <CAGpuCi7Yh=
> CtgA8fPmKx28v8qttWMiqj1jHgA7H9otyrZg72Fw at mail.gmail.com>
> 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 <flavio.etrusco at gmail.com>
> To: james at productionautomation.net, FPC-Pascal users discussions
> <fpc-pascal at lists.freepascal.org>
> Cc: James Richters <james.richters at productionautomation.net>
> Subject: Re: [fpc-pascal] TIniFile crash
> Message-ID:
> <CAJvBmOYK=m=
> d_19POP9GPxud6wc8ja44RHHJtzTuXZx_Uw4Dzw at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> Em sex., 1 de ago. de 2025, 17:54, James Richters via fpc-pascal <
> fpc-pascal at lists.freepascal.org> 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 - fpc-pascal at lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
>
>
> ------------------------------
>
> End of fpc-pascal Digest, Vol 254, Issue 3
> ******************************************
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20250802/4f4f7962/attachment.htm>
More information about the fpc-pascal
mailing list