delphi – 如何从INI文件存储和读取数组?
发布时间:2020-12-15 09:11:01 所属栏目:大数据 来源:网络整理
导读:如何在ini文件中将一个数组写入一个Ident,最近如何从中读取并将值存储在数组中? 这就是我喜欢ini的样子: [TestSection]val1 = 1,2,3,4,5,6,7 我遇到的问题: 我不知道我必须使用的功能 尺寸不是静态的.它可能超过7个值,可能更小.我如何检查长度? 解决方法
如何在ini文件中将一个数组写入一个Ident,最近如何从中读取并将值存储在数组中?
这就是我喜欢ini的样子: [TestSection] val1 = 1,2,3,4,5,6,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',''); //show results showMessage('Found ' + intToStr(MyList.count) + ' items ' + MyList.commaText); finally IniFile.Free; end; finally FreeAndNil(MyList); end; end; 您必须将整数保存并加载为CSV字符串,因为没有内置函数可以将数组直接保存到ini文件中. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |