当值是一个引用字符串,引号(“)被自动删除。TIniFile.WriteString(科键,值)改变值自动
这意味着,下面的语句二, A.WriteString('Section','Key','"abcde"')
和 A.WriteString('Section','Key','abcde')
没有什么两样
请看看我的代码(这是很清楚)。
program project1;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes, IniFiles, sysutils
{ you can add units after this };
var
List: TIniFile;
A, B: String;
begin
List := TIniFile.Create('file.ini');
A := '"abcde"';
List.WriteString('Section', 'Key', A);
List.Free;
List := TIniFile.Create('file.ini');
B := List.ReadString('Section', 'Key', '');
List.Free;
if A<>B then raise Exception.Create(Format('A<>B (A=[%s] but B=[%s])', [A, B]));
end.
上面的代码提高FOL下降的例外:A<>B (A=["abcde"] but B=[abcde])
我想这样编码:A.WriteString('Section', 'Key', List.CommaText);
因为List.CommaText
可能是一个带引号的字符串,所以我没有如上所述的代码解决方案。
它是一个错误或功能?如何将TStrings
保存到TIniFile
?
可以扩大这一点位? –
那么,继续前进,并将其放入你的答案,所以它更清晰:) –