RT
比如要读取注册表
Software\Microsoft\Windows\Run下面的所有键,然后全部列出项目名称和项目值.第二:
读取INI
Section确定.项目名确定,项目后面的数量不确定,也是需要列出项目的数量,然后得到挨个项目后面的值
[Application]
Program1=xxxxxxxxx
Program2=xxxxxxxxx
Program3=xxxxxxxxx
ProgramN=xxxxxxxxx谢谢大家讨论.
比如要读取注册表
Software\Microsoft\Windows\Run下面的所有键,然后全部列出项目名称和项目值.第二:
读取INI
Section确定.项目名确定,项目后面的数量不确定,也是需要列出项目的数量,然后得到挨个项目后面的值
[Application]
Program1=xxxxxxxxx
Program2=xxxxxxxxx
Program3=xxxxxxxxx
ProgramN=xxxxxxxxx谢谢大家讨论.
要使用TiniFile类,必须在使用该类的单元文件中用Uses inifiles指令明确地说明。
TiniFile类中定义了许多成员函数,这里介绍几个使用频率较高的成员函数:
⑴ Create()
函数定义为: constructor Create(const FileName: string);
该函数建立TiniFile类的对象。参数FileName是要读写的初始化文件名。
若读写的文件在Windows的目录里(如system.ini文件),则可以直接写文件名而不必指定路径,否则就必须指定路径(如d:\ucdos\rdfnt.ini)。
⑵ ReadSections()
过程定义为: procedure ReadSections(Strings: TStrings);
该过程将从所建立的TiniFile类的对象(即与之关联的初始化文件)中读取所有的节点名(即用[]括号括起的那部分,如rdfnt.ini文件中的[True Type fonts list])存入字符串列表中。参数Strings即为字符串列表的变量名。
⑶ ReadSectionValues()
过程定义为: procedure ReadSectionValues(const Section: string; Strings: TStrings);
该过程将参数Section的值所对应的节点(如rdfnt.ini文件中的[True Type fonts list])中的各个关键字(如ARIALBI.TTF)及其所含的值(如ARIALBI.TTF关键字值为67)读入参数Strings指明的字符串列表中。
⑷ ReadSection()
过程定义为: procedure ReadSection(const Section: string; Strings: TStrings);
该过程将参数Section的值所对应的节点中的各个关键字读入参数Strings指明的字符串列表中。与ReadSectionValues()不同的是它没有读取各个关键字的对应值。
⑸ ReadString()
函数定义为: function ReadString(const Section, Ident, Default: string): string;
该函数返回以参数Section的值为节点名、参数Ident的值为关键字名所对应的关键字值(如[True Type fonts list]节中ARIALBI.TTF关键字的值为67)。当指定的节点或节内的关键字不存在时,则函数返回参数Default的缺省值。返回的值是一个字符串型数据。
当指定节点中关键字值的数据类型不是字符串时,则可用ReadInteger()成员函数读取一个整型值,用ReadBool()成员函数读取一个布尔值。
⑹ WriteString()
过程定义为: procedure WriteString(const Section, Ident, Value: string);
该过程将参数Section的值为节点名、参数Ident的值为关键字名的关键字值设置为参数Value的值。该过程设置的是字符串型数据。
当指定节点和关键字均存在时,则用Value的值替代原值;如指定节点不存在,则在关联的初始化文件中自动增加一个节点,该节点的值为参数Section的值,并在该节点下自动增加一个关键字,关键字名为参数Ident的值,该关键字对应的值为参数Value的值;若节点存在,但关键字不存在,则在该节点下自动增加一个关键字,关键字名为参数Ident的值,该关键字对应的值为参数Value的值。
若要设置整型值,可调用WriteInteger()成员函数;用WriteBool()成员函数设置布尔值。
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls,inifiles;type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Timer1: TTimer;
CheckBox1: TCheckBox;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button1Click(Sender: TObject);
// procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation
var
MyIniFile:TIniFile;
startnum:integer;
{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
var filename:string;
begin
{下面两行的书写形式,在应用程序的路径下创建ini文件}
filename:=ExtractFilePath(paramstr(0))+'myini.ini';
myinifile:=TiniFile.create(filename);
edit1.Text:=myinifile.ReadString('newini','用户名称','');
edit2.text:=inttostr(myinifile.readinteger('newini','已运行次数',0));
if myinifile.readinteger('newini','是否正式用户',0)=1 then
checkbox1.Checked:=true
else checkbox1.Checked:=false;
//checkbox1.Checked:=myinifile.readbool;
{newini是小节名字,中间字段是关键字的名字,第三个字段是缺省值。当myini.ini不存在时,上面的语句自动创建这个文件,上边几行里的引号是单引号}
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
myinifile.writestring('newini','用户名称',edit1.Text);
myinifile.writeinteger('newini','已运行次数',strtoint(edit2.text)+1);
myinifile.writebool('newini','是否正式用户',checkbox1.Checked);
myinifile.Destroy;//特别注意
end;
{procedure TForm1.Timer1Timer(Sender: TObject);
begin
edit2.Text:=inttostr(strtoint(edit2.text)+1);
end;}procedure TForm1.Button1Click(Sender: TObject);
begin
close;
end;end.
Kevin_Lmx(繁华阅尽)答的很詳細了! 缺少的是自己去嚐試!