阅读 INI 文件部分以 Delphi returns 中的注释开头一个空列表
Reading INI files section starting with a comment in Delphi returns an empty list
简化的Delphi代码:
var
AppSettings: TIniFile;
Camera: TStringList;
begin
AppSettings := TIniFile.Create(ChangeFileExt(Application.ExeName, '.ini'));
Camera := TStringList.Create;
AppSettings.ReadSectionValues('Camera', Camera);
FreeAndNil(Camera);
FreeAndNil(AppSettings);
end;
简化的 INI 文件内容:
[Camera]
; A commented line
SomeKey=SomeValue
AnotherKey=AnotherVal
目前 TStringList
是空的,因为 INI 中该部分开头的注释行,但我希望 Count
为 2。
有没有办法加载 Delphi 中存在注释行 (;
) 的 INI 文件部分?
我在 Windows 10 上使用 Delphi 10.3.2。INI 文件的行尾是 #13#10
(\r\n
).
刚刚将上面示例中的 TIniFile
替换为 TMemIniFile
,现在 ReadSectionValues
returns 是正确的结果。
简化的Delphi代码:
var
AppSettings: TIniFile;
Camera: TStringList;
begin
AppSettings := TIniFile.Create(ChangeFileExt(Application.ExeName, '.ini'));
Camera := TStringList.Create;
AppSettings.ReadSectionValues('Camera', Camera);
FreeAndNil(Camera);
FreeAndNil(AppSettings);
end;
简化的 INI 文件内容:
[Camera]
; A commented line
SomeKey=SomeValue
AnotherKey=AnotherVal
目前 TStringList
是空的,因为 INI 中该部分开头的注释行,但我希望 Count
为 2。
有没有办法加载 Delphi 中存在注释行 (;
) 的 INI 文件部分?
我在 Windows 10 上使用 Delphi 10.3.2。INI 文件的行尾是 #13#10
(\r\n
).
刚刚将上面示例中的 TIniFile
替换为 TMemIniFile
,现在 ReadSectionValues
returns 是正确的结果。