Modify

Opened 15 years ago

Closed 15 years ago

Last modified 15 years ago

#939 closed Bug (No Bug)

IniRenameSection fails with "empty" section

Reported by: MrCreatoR <mscreator@…> Owned by:
Milestone: Component: AutoIt
Version: 3.3.0.0 Severity: None
Keywords: Cc:

Description

When we trying to rename an empty section (just section name without keys), we get the same results as when the section not exists at all.

$iRet = IniRenameSection("Test.ini", "Old Sect", "New Sect", 1)

ConsoleWrite("$iRet: " & $iRet & @CRLF & "@error: " & @error)

But IniDelete works just fine with this same section.

If this is not a bug and it's expected behaviour, then i think this (that IniRenameSection renames section only with keys in it) should be mentioned in the documents at least.

[Forum topic http://www.autoitscript.com/forum/index.php?s=&showtopic=94153&view=findpost&p=676398]

Attachments (0)

Change History (6)

comment:1 follow-up: Changed 15 years ago by Valik

  • Resolution set to No Bug
  • Status changed from new to closed

What does it matter? An empty section or a section that does not exist are functionally equivalent. I don't see that it needs documented.

comment:2 in reply to: ↑ 1 Changed 15 years ago by MrCreatoR <mscreator@…>

Replying to Valik:

What does it matter? An empty section or a section that does not exist are functionally equivalent. I don't see that it needs documented.

Then why IniDelete does work with it? And sometimes there is need to work with empty sections along with the other, for example, i am using it for a seperater in list (between "category" entries).

It's confusing, and imo it's wrong. Newbies will have dificulties to understand why it's not working, it's took me a while to understand :)

comment:3 Changed 15 years ago by Valik

An empty section has no content to move so it does nothing. This is not an error. The section does exist, it's just empty. That is why IniDelete() works.

As I expected, you are writing bad code and trying to rely on things you shouldn't. An empty section should be treated like a section that does not exist. It's more reliable to write code that makes that assumption. Second, you must be exceedingly careful how you generate the INI file if you are attempting to rely on the order of sections as some sort of order for the way they should appear. A much better solution is to have a "Main" section which stores the order in key=value pair. That will give you guaranteed control over the order.

In short, your code sounds questionable. AutoIt is not doing anything wrong here.

comment:4 Changed 15 years ago by MrCreatoR <mscreator@…>

you are writing bad code and trying to rely on things you shouldn't

I am relyig on things that sound logic to me, that's it. Now i will know that this is not always good idea (to rely on (my?) logic :) ).

P.S
IniRenameSection does rename with such content:

[Section]
Key

I mean without a value to the key, and i understand that the function checks for the content inside the section, and don't check if the section having a correct content. I just having difficulties to understand why it can not rename with the same logic (without checking the content at all).

A much better solution is to have a "Main" section which stores the order in key=value pair

Then i will have to write functions to move/rename each "key=value" in case i ("the user") will need to change the order. Perhaps there is a way to do what i need in much smart and sefisticated way, but i just wanded to stay with the simplest and quickest way, and i didn't thought that i will have problems with the Ini* funcs.

comment:5 Changed 15 years ago by Valik

The underlying Windows API returns the number of bytes read (when reading the existing section). An empty section returns 0 characters. A non-existent section returns 0 characters. See the problem?

comment:6 Changed 15 years ago by MrCreatoR <mscreator@…>

See the problem?

Yes.
I really appreciating the attention to the subject, and sorry for wasting your time.

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The ticket will remain with no owner.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.