delphi 怎样获得ini文件的小节数和小节里的项目数

cyxlsm 2005-03-21 04:53:54
请问delphi 怎样获得ini文件的小节数和小节里的项目数,请高手帮我,谢谢:)
...全文
555 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
Skcmacau 2005-05-22
  • 打赏
  • 举报
回复
我想問 如果我的ini文件是:
[x]
x=x
[xx]
xx=xx
[xxx]
xxx=xxx
[xxxx]
xxxx=xxxx
這樣子 我有4個小節 現在我想把小節數賦值給num 這時num應該等於4
這個怎樣做呢?
SStallMan 2005-03-27
  • 打赏
  • 举报
回复 1


s1 := TStringList.create ; //s1 是小节
s2 := TStringList.create ;//s2 是每个小节里面的键值
try
myinifile.ReadSections ( s1 ) ; //

for j := 0 to s1.Count - 1 do
begin
lst1.Items.Append ( s1 [ j ] ) ; //是一个TStringList对象 ,s1[j]取出值,lst1
//是TListBox对象,在这个基础上改一改不难了把
myinifile.ReadSectionValues ( s1 [ j ] , s2 ) ;

for k := 0 to s2.Count - 1 do
begin
lst1.Items.Append ( ' ' + s2 [ k ] ) ;
end ;

end ;
finally
s1.Free ;
s2.Free ;
end ;
cyxlsm 2005-03-21
  • 打赏
  • 举报
回复
[一工位]
1=外检
2=废气
3=烟度
5=灯光
[二工位]
4=侧滑
6=声级
[三工位]
7=轴重
8=制动

我的ini文件如上,我想把小节的名字,“一工位,二工位,三工位”分别提出来赋给一个字符串变量,怎么呢?
swordxy 2005-03-21
  • 打赏
  • 举报
回复
sxy_9761() 说的:

ini.ReadSectionValues(Sections[0],Sections);

=======
可以根据 Sections[0] 换成不同的索引来读取。
cyxlsm 2005-03-21
  • 打赏
  • 举报
回复
谢谢,还有一点疑问,我想获得每个小节的名字,怎么办呢?
sxy_9761 2005-03-21
  • 打赏
  • 举报
回复
procedure TForm1.Button1Click(Sender: TObject);
var
ini : TIniFile;
Sections : TStringList;
begin
if OpenDialog.Execute then
begin
ini := TIniFile.Create(OpenDialog.FileName);
Sections := TStringList.Create;
ini.ReadSections(Sections);
ShowMessagefmt('Section Count: %d',[Sections.Count]);
ini.ReadSectionValues(Sections[0],Sections);
ShowMessagefmt('Id of Section[0] Count:%d',[Sections.Count]);
Sections.Free;
ini.Free;
end;
end;
acqy 2005-03-21
  • 打赏
  • 举报
回复
uses IniFiles;

var ini: TIniFile;
begin
ini := TIniFile.Create('c:\test.ini');
ini.ReadSections (...) //读取小节数
ini.ReadSectionValues (...) //读取小节中的项目数
end;
alec_ma 2005-03-21
  • 打赏
  • 举报
回复
看源代码吧

5,928

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧