Discussion:
Comments in Ini files?
(too old to reply)
Raptor
2005-02-19 03:31:43 UTC
Permalink
Anyone know if there's provision for adding comments to Ini files (IniFiles
unit), other than maybe faking it with a [COMMENTS] and CommentNN= lines?

I'm using them in my Translate unit, which is working out very nicely so
far, and it might be handy to place instructions at the top for translators.

Raptor
Rod
2005-02-19 04:07:42 UTC
Permalink
I believe you'll find that the standard convention (used by Microsoft)
is to precede any comments with a semicolon.
Post by Raptor
Anyone know if there's provision for adding comments to Ini files (IniFiles
unit), other than maybe faking it with a [COMMENTS] and CommentNN= lines?
I'm using them in my Translate unit, which is working out very nicely so
far, and it might be handy to place instructions at the top for translators.
Raptor
Raptor
2005-02-19 08:52:25 UTC
Permalink
Post by Rod
I believe you'll find that the standard convention (used by Microsoft)
is to precede any comments with a semicolon.
Sure... I should have just looked in some of the 200 or so on my system. I
found several right off with semicolon commented lines. There's an example
of the overlooking-the-obvious we talked about.

I hope the Delphi unit follows that practice. Thanks.

Raptor
Rod
2005-02-19 19:52:56 UTC
Permalink
Post by Raptor
Post by Rod
I believe you'll find that the standard convention (used by Microsoft)
is to precede any comments with a semicolon.
Sure... I should have just looked in some of the 200 or so on my system. I
found several right off with semicolon commented lines. There's an example
of the overlooking-the-obvious we talked about.
I hope the Delphi unit follows that practice. Thanks.
Raptor
Pete
2005-02-25 19:37:59 UTC
Permalink
Post by Rod
I believe you'll find that the standard convention (used by Microsoft)
is to precede any comments with a semicolon.
<snip>
I hope the Delphi unit follows that practice. Thanks.
I think you're asking for trouble. If you, for example, delete a commented
section from an INI file, then replace the section with new data, I'd guess
the comments stay in the old location and the new section goes at the end
of the file. Furthermore, there's no provision in TIniFile to write a
comment.

I could be wrong on this, 'cos I haven't taken the time to test it.

Pete
Raptor
2005-02-25 20:23:52 UTC
Permalink
Post by Pete
<snip>
I hope the Delphi unit follows that practice. Thanks.
I think you're asking for trouble. If you, for example, delete a commented
section from an INI file, then replace the section with new data, I'd guess
the comments stay in the old location and the new section goes at the end
of the file. Furthermore, there's no provision in TIniFile to write a
comment.
I could be wrong on this, 'cos I haven't taken the time to test it.
I assumed, Pete, that there may be unknown consequences to just adding
comments willy-nilly. I just looked through the source of IniFiles.pas,
though, and don't imagine that adding formal comment-handling provisions
will be all that difficult.

It's only four or five pages of largely repetitive code.

Concerns appreciated.

Nathan
Rob Kennedy
2005-02-25 20:53:23 UTC
Permalink
Post by Raptor
I assumed, Pete, that there may be unknown consequences to just adding
comments willy-nilly. I just looked through the source of IniFiles.pas,
though, and don't imagine that adding formal comment-handling provisions
will be all that difficult.
You might consider TBigINIFile, by Edy Hinzen. It has several
comment-related methods.

http://www.hinzen.de/delphi/index.html
--
Rob
Raptor
2005-02-25 21:35:55 UTC
Permalink
Post by Rob Kennedy
Post by Raptor
I assumed, Pete, that there may be unknown consequences to just adding
comments willy-nilly. I just looked through the source of IniFiles.pas,
though, and don't imagine that adding formal comment-handling provisions
will be all that difficult.
You might consider TBigINIFile, by Edy Hinzen. It has several
comment-related methods.
http://www.hinzen.de/delphi/index.html
Thanks, Rob. Now that you mention it, I have come across a couple of
IniFiles substitutes/derivatives in my searches, and this one sounds
familiar. I'll have a look.

Nathan
a***@aol.com
2005-02-26 07:16:21 UTC
Permalink
TIniFile appears (in D3) to be just a wrapper for GetPrivateProfile*
API calls. So any comment handling is that inherent in those calls.

There is only a couple of references to comments (semi-colon prefixed
lines) in MSDN. One for GetPrivateProfileSection says that WinNT/200
strips comments but Win95/98 includes comments.

This is certainly wrong for GetPrivateProfileSectionNames because I
hand commented whole sections in an ini-file and the section was not
included in TIniFile.ReadSections (Win98SE).

There is a warning in WritePrivateProfileSection about value comments
being possibly out of order in the section after a value has been
re-written.

Alan Lloyd
Raptor
2005-02-26 07:37:15 UTC
Permalink
Post by a***@aol.com
TIniFile appears (in D3) to be just a wrapper for GetPrivateProfile*
API calls. So any comment handling is that inherent in those calls.
There is only a couple of references to comments (semi-colon prefixed
lines) in MSDN. One for GetPrivateProfileSection says that WinNT/200
strips comments but Win95/98 includes comments.
This is certainly wrong for GetPrivateProfileSectionNames because I
hand commented whole sections in an ini-file and the section was not
included in TIniFile.ReadSections (Win98SE).
There is a warning in WritePrivateProfileSection about value comments
being possibly out of order in the section after a value has been
re-written.
Thanks, Alan. I'll factor this in when I get back to that part of my
project.

Nathan
J French
2005-02-26 08:51:09 UTC
Permalink
On Fri, 25 Feb 2005 23:37:15 -0800, "Raptor" <***@none.com> wrote:

<snip>
Post by Raptor
Thanks, Alan. I'll factor this in when I get back to that part of my
project.
You would also be wise to look at TMemIniFile which is part of D4 and
does /not/ rely on the APIs

I've not done this with Win32, but under Win16 I wrote a file snooper
and watched what the APIs were doing on disk with INI files

It was ... interesting ....

Before 'sealing' things I suggest you run FileMon against your App

Personally I wrote my own class for handling INI files, and just
regard them as an extended form of 'data handling'
Raptor
2005-02-26 10:24:47 UTC
Permalink
<snip>
Post by Raptor
Thanks, Alan. I'll factor this in when I get back to that part of my
project.
You would also be wise to look at TMemIniFile which is part of D4 and
does /not/ rely on the APIs
Will do.
Before 'sealing' things I suggest you run FileMon against your App
And be on the lookout for...?
Personally I wrote my own class for handling INI files, and just
regard them as an extended form of 'data handling'
That's what it boils down to, doesn't it? Thanks, JF.

R

Continue reading on narkive:
Loading...