Modify

Opened 16 years ago

Closed 16 years ago

Last modified 16 years ago

#644 closed Feature Request (Rejected)

Can IniRead set @error for file/section/key not exist?

Reported by: Rob Saunders <therks@…> Owned by:
Milestone: Component: AutoIt
Version: Severity: None
Keywords: iniread @error default Cc:

Description

Is there any chance we could have IniRead set @error (or even @extended) when it has to resort to the default value?
Maybe something like:

Success: Returns the requested key value.
Failure: Returns the default string if requested key not found and sets @error.

@error
1Filename invalid/does not exist
2Section invalid/does not exist
3Key invalid/does not exist

Attachments (0)

Change History (3)

comment:1 Changed 16 years ago by Valik

  • Resolution set to Rejected
  • Status changed from new to closed

Nope. We would have to write code to handle each of those situations because the API does not provide any information about why the default string is being used. However, for 1 and 3 it's simple for you to write a wrapper function in AutoIt. Something like this is a start:

Func _IniRead($sFile, $sSection, $sKey, $sDefault)
    If Not FileExists($sFile) Then Return SetError(1, 0, $sDefault)
    Local Const $sInternalDefault = "_INIREADDEFAULTVALUE"
    Local $sResult = IniRead($sFile, $sSection, $sKey, $sInternalDefault)
    If $sResult = $sInternalDefault Then Return SetError(3, 0, $sDefault)
    Return $sResult
EndFunc

Probably the best way to handle the section names thing is just use IniReadSectionNames() and search the results array for the section name. No matter what, though, performance will suffer in testing for the section to exist.

comment:2 follow-up: Changed 16 years ago by Rob Saunders <therks@…>

Oh I didn't realize the default value was a part of the API call. I thought that was something added to the IniRead function by you guys. Is the original API call "GetPrivateProfileString"? I'm just reading about it now.

And about testing if the key value existed, I was doing something like that, but I did a double check with random numbers. (Set random number, use that for default, if equal, set another random and do it again).

An extra question though, didn't you (Valik) say once that you wanted to rewrite the Ini functions from scratch to deal with some issues they had? If you ever do get the time or inclination to do that, do you think having @error reporting like this would make it in there?

comment:3 in reply to: ↑ 2 Changed 16 years ago by Valik

Replying to Rob Saunders <therks@…>:

Is the original API call "GetPrivateProfileString"? I'm just reading about it now.

It is.

An extra question though, didn't you (Valik) say once that you wanted to rewrite the Ini functions from scratch to deal with some issues they had?

See #15.

If you ever do get the time or inclination to do that, do you think having @error reporting like this would make it in there?

I do not know.

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.