Delphi中如何高效地从INI文件中存储和读取大量数组数据?
- 内容介绍
- 文章标签
- 相关推荐
本文共计290个文字,预计阅读时间需要2分钟。
在ini文件中,将一个数组写入一个Ident,最近如何从中读取并存储值到数组中?
这是我喜欢ini文件的样式:[TestSection]val1=1,2,3,4,5,6,7
遇到的问题:我不知道我必须使用的功能+ 尺寸“
如何在ini文件中将一个数组写入一个Ident,最近如何从中读取并将值存储在数组中?这就是我喜欢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文件中.
本文共计290个文字,预计阅读时间需要2分钟。
在ini文件中,将一个数组写入一个Ident,最近如何从中读取并存储值到数组中?
这是我喜欢ini文件的样式:[TestSection]val1=1,2,3,4,5,6,7
遇到的问题:我不知道我必须使用的功能+ 尺寸“
如何在ini文件中将一个数组写入一个Ident,最近如何从中读取并将值存储在数组中?这就是我喜欢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文件中.

