Ini file wikipedia
Some rudimentary programs do not allow blank lines. Every line must therefore be a section head, a parameter and value pair, or a comment.
Interpretation of whitespace varies. Most implementations ignore leading and trailing whitespace around the outside of the parameter name. Some even ignore whitespace within value names for example, making "host name" and "hostname" equivalent. Some implementations also ignore leading and trailing whitespace around the parameter value; others consider all characters following the equals sign including whitespace to be part of the value.
The standard Windows function GetPrivateProfileString supports this, and will remove quotation marks that surround the values. Some software supports the use of the number sign as an alternative to the semicolon for indicating comments. In some implementations, a comment may begin anywhere on a line, including on the same line after parameters or section declarations.
In others, any comments must occur on lines by themselves. Most implementations only support having one parameter with a given name in a section. The second occurrence of a parameter name may cause an abort ; the second occurrence may be ignored and the value discarded ; the second occurrence may override the first occurrence discard the first value. Some programs use duplicate parameter names to implement multi-valued parameters. Interpretation of multiple section declarations with the same name also varies.
In some implementations, duplicate sections simply merge their parameters together, as if they occurred contiguously. Others may abort, or ignore some aspect of the INI file. Most commonly, INI files have no hierarchy of sections within sections. Some files appear to have a heirarchical naming convention, however. It is unclear whether these are simply naming conventions that an application happens to use in order to give the appearance of a hierarchy, or whether the file is being read by a module that actually presents this hierarchy to the application programmer.
Some support "line continuation", where a backslash followed immediately by EOL end-of-line causes the line break to be ignored, and the "logical line" to be continued on the next actual line from the INI file. Implementation of various "special characters" with sequences escapes is also seen.
Following is an example INI file for an imaginary program. It has two sections, one for the owner of the software, and one for a payroll database connection. For example, the GetPrivateProfileString function retrieves a string from the specified section in an initialization file. The following sample program demonstrates reading parameter values from the above sample INI file Let the name of configuration file be dbsettings. It was introduced with Windows NT and Windows 95 as a way to migrate from storing settings in classic.
Using the Example above, a string call could be made to fetch the name key from the owner section from a settings file called, say, dbsettings. The returned value should be the string "John Doe":. INI mapping takes this Profile API call, ignores any path in the given filename and checks to see if there is a Registry key matching the filename under:.
If this exists, it looks for an entry name matching the requested section. If an entry is found INI mapping uses the corresponding entry data as a pointer to another part of the Registry. It then looks up the requested INI setting in that part of the Registry. If no matching entry name is found and there is entry data under the Default entry name, INI mapping uses that data instead.
Thus each section name does not need its own entry. The value of "John Doe" is then returned to the Profile call. CaseSensitive - This property allows you to say if the keys and sections are case sensitive or not. By default they aren't. ReadString - Has 3 constant statements. The first one is the section to search in.
The second one is the key to look for. WriteString - has three constant statements, too. The first is the section. The second is the key and the last is the value that you want to write. If the key and section exist already, the key will be overwritten with the new value..
Jump to: navigation , search. Create IniFile ; Settings. Free ; end ; procedure TForm1. Create IniFile ; Sett. Checked ; Sett. WriteInteger 'Main' , 'X' , Settings.
X ; Sett. MyName ; Sett. Free ; end ;. ShowSettings ; begin Memo1. Clear ; Memo1. MyName ; Memo1. Checked , true ; end ; procedure TForm1. Create 'DB. Free ; end ; end.
0コメント