Ahk Board Topic

Class to perform Ini reading and writing operations
Created as a complete replacement of the default Ini commands

  • Much much faster than the default Ini operations.
  • Support for reading/writing linked comments to keys and sections.
  • Same syntax as the default Ini commands.

Example of an Ini created through the lib

[section1]
;section1 comment
key1 = hithere_key1

;keycomment
;line2
;line3
key2 = hithere_key2

;keycomment2
key3 = hithere_key3

 
[section2]
;section2 comment
key1 = hithere2

;keycomment2

The code

SetWorkingDir,% A_scriptdir
 
Ini := new AhkIni("black2.ini")		;will create new ini if nothing exists
 
ini.write("section1", "key1", "hithere_key1", "keycomment`nline2`nline3")
ini.write("section1", "key2", "hithere_key2", "keycomment2", "section1 comment")
ini.write("section1", "key3", "hithere_key3")	;no comment for this key
ini.write("section2", "key1", "hithere2", "keycomment2", "section2 comment")
 
msgbox,% ini.read("section1", "key1", key, sec) "`n`n" key "`n`n" sec
msgbox,% "Section1 keys are `n`n" ini.read("section1")		;read the keys in section 1
msgbox,% "Sections in the ini are`n`n" ini.read()
;ini.delete("section1", "key1")		;delete the above read key
 
ini.Save()
 
#include, AhkIni.ahk



Methods

  • New(Inifile)

    Sets a pointer to an Ini settings file.
    The Ini file is created if it doesn't exists.

  • .Read(Section="", Key="", Byref Key_com="", ByRef Sec_com="")

    Reads value of the Key contained in a Section to the outputvar.
    If the Byref parameters are specified, the linked Key comments (Key_com) and Section comments (Sec_com) are also read.
    If Section="" i.e. the first param is unspecified, the list of sections in the ini will be returned in a fashion similar to the AHK_l IniRead command.
    If Key="" , the list of Keys in the specified Section is returned.

  • .Write(Section, Key, Value, Key_com="", Sec_com="")

    Write values to a key, creating the key and section if necessary.
    The params Key_com and Sec_com are for key and section comments.
    If these params are omitted, then the original corresponding comment is left unchanged but if
    these params are called as a Space (" " or A_space), then the linked comment for the section/key is deleted and changed to null.

  • .Delete(Section="", Key="")

    Delete keys or sections from the ini.
    If Key is omitted , the whole section is deleted.
    If Section is omitted , the whole Ini is deleted.

  • .Save()

    Saves the changes made to the Ini made in memory to the file.
    Remember to call .Save after making the changes.