如何在ini文件中将一个数组写入一个Ident,最近如何从中读取并将值存储在数组中? 这就是我喜欢ini的样子: [TestSection]val1 = 1,2,3,4,5,6,7 我遇到的问题: 我不知道我必须使用的功能 尺寸
这就是我喜欢ini的样子:
[TestSection] val1 = 1,2,3,4,5,6,7
我遇到的问题:
>我不知道我必须使用的功能
>尺寸不是静态的.它可能超过7个值,可能更小.我如何检查长度?
uses inifiles
procedure ReadINIfile
var
IniFile : TIniFile;
MyList:TStringList;
begin
MyList := TStringList.Create();
try
MyList.Add(IntToStr(1));
MyList.Add(IntToStr(2));
MyList.Add(IntToStr(3));
IniFile := TIniFile.Create(ChangeFileExt(Application.ExeName,'.ini'));
try
//write to the file
IniFile.WriteString('TestSection','Val1',MyList.commaText);
//read from the file
MyList.commaText := IniFile.ReadString('TestSection','Val1','');
//show results
showMessage('Found ' + intToStr(MyList.count) + ' items '
+ MyList.commaText);
finally
IniFile.Free;
end;
finally
FreeAndNil(MyList);
end;
end;
您必须将整数保存并加载为CSV字符串,因为没有内置函数可以将数组直接保存到ini文件中.
