怎么样获取INI文件中写的节点的个数

修哲 2005-11-29 04:29:31
我想循环读取INI文件里个节点,我想知道节点的个数,请问高手们怎么解决?
...全文
510 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
leonkim 2005-11-29
  • 打赏
  • 举报
回复
ReadSections
pcov1018 2005-11-29
  • 打赏
  • 举报
回复
在uses 中用inifiles ,'d:\myini.ini'建立文件就可以了, ComboBox1.Items.Count 里面就是节点个数
procedure TForm1.Button1Click(Sender: TObject);
var
myini : TiniFile;
begin
Myini := TiniFile.Create('d:\myini.ini');
myini.ReadSections(ComboBox1.Items);
end;
g961681 2005-11-29
  • 打赏
  • 举报
回复
其实就是ReadSection和ReadSections两个特殊方法的事~~~~~~
g961681 2005-11-29
  • 打赏
  • 举报
回复
unit Main;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, IniFiles,
StdCtrls;

type
TForm1 = class(TForm)
ListBox1: TListBox;
ListBox2: TListBox;
Edit1: TEdit;
procedure FormCreate(Sender: TObject);
procedure ListBox1Click(Sender: TObject);
procedure ListBox2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
with TIniFile.Create(ChangeFileExt(Application.ExeName, '.ini')) do
try
ReadSections(ListBox1.Items);
finally
Free;
end;
end;

procedure TForm1.ListBox1Click(Sender: TObject);
var
sSection: String;
begin
if ListBox1.ItemIndex < 0 then Exit;
sSection := ListBox1.Items.Strings[ListBox1.ItemIndex];
ListBox2.Items.Clear;
with TIniFile.Create(ChangeFileExt(Application.ExeName, '.ini')) do
try
ReadSection(sSection, ListBox2.Items);
finally
Free;
end;
end;

procedure TForm1.ListBox2Click(Sender: TObject);
var
sSection, sIdent: String;
begin
if ListBox1.ItemIndex < 0 then Exit;
if ListBox2.ItemIndex < 0 then Exit;
sSection := ListBox1.Items.Strings[ListBox1.ItemIndex];
sIdent := ListBox2.Items.Strings[ListBox2.ItemIndex];
with TIniFile.Create(ChangeFileExt(Application.ExeName, '.ini')) do
try
Edit1.Text := ReadString(sSection, sIdent, 'Error');
finally
Free;
end;
end;

end.
修哲 2005-11-29
  • 打赏
  • 举报
回复
怎么没人回呀,我急呀,高手们,快点帮小弟一个忙把

16,742

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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