| |||
Updating and Adding Items Updating individual values is similar to retrieving them. You provide a section name, a key name, and the new value. The class uses the GetItem method to locate the appropriate <item> element, and then updates that item@#s value attribute with the specified new value. The Windows API function WritePrivateProfileString creates new sections and items if you call it with a section or key name that doesn@#t already exist. Although it@#s not good object-oriented design, for consistency the IniFileReader class acts identically, meaning that you can create a new section simply by passing a nonexistent section name. To update a section name, key name, or value for existing sections or items, select the section and item you want to update, enter the new values in the appropriate fields, and then click the Update button to apply the changes. To create a new section or key on the sample form, first click the New Section or New Key button to clear the current selections, and then enter the new section or key name and click the Update button to apply your changes. To delete a section using the API, you pass the section name and a null key value to the WritePrivateProfileString function—and you do the same with the IniFileReader class, except that you use the SetIniValue method. For example, the following code would delete the section named section1. SetIniValue("section1", null, null);Similarly, to delete an item within a section, you pass the section name, the key name, and a null value for the value argument. The following code would delete the item with the key key1 in the section named section1. SetIniValue("section1", "key1", null);On the sample form (see ), you can delete a section or value by selecting the appropriate item in either the section or item list, and then pressing the Delete key.
Second, the XmlDoc property gives the calling code direct aclearcase/" target="_blank" >ccess to the underlying XmlDocument object. The IniFileReader class has a number of properties that extend the standard API functionality. For example, the GetAllSections method retrieves all the section names. Whenever the class returns multiple values, it returns a StringCollection object rather than a string array. While this marginally affects the class@#s performance, from the caller point of view, StringCollections are more convenient than simple arrays. |