TIniFile.ReadSectionValues ultimately uses the Windows API function GetPrivateProfileString to read key values from the ini file. GetPrivateProfileString will remove any start and end white space, as well as any quotation marks surrounding the string.
That means the string
[ key = value1 value2 value3 ]
will return the same value as the string
[ key=value1 value2 value3 ]
(square brackets added to show extra spaces).
To preserve any leading and trailing spaces, you will have to enclose your lines in single or double quotation marks when writing them back to ini.
Since GetPrivateProfileString removes any surrounding quotes (single or double), you do not need to remove them when you read the values from the ini file.
To add quotes, you should NOT use the AnsiQuotedStr function, as François mentioned ( change , unless you take special care to select a char quote, which is very unlikely in the string in the first place). AnsiQuotedStr will add surrounding double quotes, but will also double any double quotes already on the line. Although this is the desired behavior when you subsequently use AnsiDequoteStr, it is not when you use TIniFile to read values, since GetPrivateProfileString removes the surrounding quota labels, but will not release the built-in ones.
So, if you are going to read values from a file using TIniFile and want to keep leading and trailing spaces, you will need to add surrounding quotes yourself and make sure that any embedded quotes are not doubled (or you will have to de-double them after reading them with TIniFile).
Marjan venema
source share