【发布时间】:2014-04-07 15:34:58
【问题描述】:
当 Value 是带引号的字符串时,引号 (") 会被自动删除。
这意味着,以下两个语句,
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.
前面的代码引发以下异常:A<>B (A=["abcde"] but B=[abcde])
我想编写如下代码:A.WriteString('Section', 'Key', List.CommaText); 因为List.CommaText 可能是带引号的字符串,所以我没有解决上述代码的方法。
是错误还是功能?如何将TStrings 保存到TIniFile?
【问题讨论】:
标签: lazarus tstringlist