打印本文 打印本文 关闭窗口 关闭窗口
Delphi中初始化.Ini文件的读写
作者:武汉SEO闵涛  文章来源:敏韬网  点击数1887  更新时间:2009/4/23 18:42:14  文章录入:mintao  责任编辑:mintao

象,该对象用来读写d:\ucdos目录中的rdfnt.ini文件,

如果读写的文件在Windows的目录里(如system.ini),

则可以直接写文件名而不必指定路径 }

  IniFile:=TIniFile.Create(''''d:\ucdos\rdfnt.ini'''');

{ 将TIniFile对象关联的初始化文件system.ini中的所

有节(即用[]括号括起的那部分)的节名送入下拉式组

合列表框SectionComboBox中 }

  SectionComboBox.Clear;

  IniFile.ReadSections(SectionComboBox.Items);

{ 选择system.ini文件的第一个节名 }

  SectionComboBox.ItemIndex:=0;

  SectionComboBoxChange(Sender);

  CmdSave.Enabled:=False;

end;

 

{ 将组合列表框IniComboBox中所选择节中对应的各个

变量及对应的值送入多行文本编辑器IniMemo中 }

procedure TIniForm.SectionComboBoxChange(Sender: TObject);

begin

  IdentComboBox.Clear;

  IniFile.ReadSection(SectionComboBox.Text,

                  IdentComboBox.Items);

  IdentComboBox.ItemIndex:=0;

  IdentComboBoxChange(Sender);

end;

 

procedure TIniForm.IdentComboBoxChange(Sender: TObject);

begin

  IdentValueEdit.Enabled:=False;

  { 将选择的关键字值读入 }

  IdentValueEdit.Text:=

      IniFile.ReadString(SectionComboBox.Text,

      IdentComboBox.Text,'''''''');

end;

 

procedure TIniForm.CmdChangClick(Sender: TObject);

begin

  CmdSave.Enabled:=True;

  IdentValueEdit.Enabled:=True;

  IdentValueEdit.SetFocus;

end;

 

procedure TIniForm.CmdSaveClick(Sender: TObject);

begin

  if IdentValueEdit.Modified then begin

    IniFile.WriteString(SectionComboBox.Text,

                        IdentComboBox.Text,

                        IdentValueEdit.Text);

  end;

  IdentValueEdit.Enabled:=False;

  CmdSave.Enabled:=False;

end;

 

procedure TIniForm.FormDestroy(Sender: TObject);

begin

  IniFile.Free;  { 释放创建的对象 }

end;

 

end.

以上方法在Windows 95下用Delphi 3.0调试通过。

上一页  [1] [2] 

打印本文 打印本文 关闭窗口 关闭窗口