unit Unit1;interfaceuses
  Windows, Messages,SysUtils, Classes, Graphics, Controls, Forms, Dialogs,inifiles,shellapi,MMSystem;type
  TForm1 = class(TForm)
    lbl_2: TLabel3D;
    procedure FormCreate(Sender: TObject);
    procedure lbl_2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
    function Get_info(i : integer) : string;
    function Get_Command(i : integer) : string;
var
  Form1: TForm1;
  AppPath : string;
  IniSettings : Tinifile;
  Old_handle : Thandle;implementation{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
appPath := copy(application.exename,1,length(application.exename) - 12);
INISettings := TINIFile.Create(AppPath+'\setup.ini');
end;function Get_info(i : integer) : string;
var
infoText : string;
begin
  infoText := IniSettings.ReadString('action'+inttostr(i),'info','');
  result := infoText;
end;function Get_Command(i : integer) : string;
var
CommandLine : string;
begin
  CommandLine := IniSettings.ReadString('action'+inttostr(i),'run','');
  result := CommandLine;
end;
procedure TForm1.lbl_2Click(Sender: TObject);
begin
shellexecuteA(Application.handle,pchar('open'),pchar(apppath+get_command(2)),nil,nil,sw_shownormal);
playsoundA('WAVE2',hInstance,SND_RESOURCE or SND_ASYNC);end;end.

解决方案 »

  1.   

    同楼上,注意要引用inifiles单元
      

  2.   

    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的值。
      

  3.   

    uses inifilesprocedure TForm1.Button1Click(Sender: TObject);
            var
            s:string ;
            iniread:String;
            initest:TInifile;
    begin
            {ini file (test.ini)
                    [test]
                    A=OK2
                    B=OK1
                    [test1]
                    A=OK1
                    B=OK2
            }
            s:=ExtractFilePath(application.exename);
            initest:=Tinifile.Create(s+'test.ini');
            //read
            iniread:=initest.ReadString('test','A','');
            iniread:=initest.ReadString('test1','A','OK1');
            //write
            initest.WriteString('test','A','OK2');
            initest.WriteString('test1','B','OK1');
            //ShowMessage(s);
    end;
      

  4.   

    uses inifilesprocedure TForm1.Button1Click(Sender: TObject);
            var
            s:string ;
            iniread:String;
            initest:TInifile;
    begin
            
            s:=ExtractFilePath(application.exename);
            initest:=Tinifile.Create(s+'test.ini');
            //read
            iniread:=initest.ReadString('test','A','');
            iniread:=initest.ReadString('test1','A','OK1');
            //write
            initest.WriteString('test','A','OK2');
            initest.WriteString('test1','B','OK1');
            //ShowMessage(s);
    end;