本地文件file.ini内容如下:
[test]
aaa=000
bbb=111
ccc=222
--------------------------------------
procedure TForm1.Button1Click(Sender: TObject);
begin
   filename:=ExtractFilePath(Paramstr(0)) + 'file.ini';
   Myfile:=Tinifile.Create(filename);
   combobox1.Items.Add('');
   combobox1.Items[0]:=myFile.Readstring('test','aaa','未定义');
end;
这样,就会根据 aaa 找到文件中的值 000 ,并显示。所以COMBOBOX1里就显示有  000。现在问题是我想根据 000 来显示 aaa ,如何做?先谢谢了!

解决方案 »

  1.   

    当然不能改变file.ini这个文件的内容。
      

  2.   

    TO : jinjazz(近身剪(N-P攻略)) :
      能具体点吗?
      

  3.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      filename :String;
      Myfile :Tinifile;
      tmpString :TStrings;
    begin
       filename:= 'c:\file.ini';
       Myfile :=Tinifile.Create(filename);
       tmpString := TStringList.Create;
       Myfile.ReadSectionValues('test',tmpString);
       showmessage(tmpString.Names[tmpString.IndexOf('aaa=000')]);
    end;
      

  4.   

    var
     xs: TStrings;
     i: integer;
    begin
     xs:= TStringList.Create;
     try
      MyFile.ReadSectionValues('test',xs);
      for i:= 0 to xs.Count-1 do 
       xs.ValueFromIndex[i]='000' then  /// ShowMessage(xs.Names[i]); 
     finally
      xs.Free;
     end;
    end;
      

  5.   

    Tstring.ValueFromIndex[i]='000' then  
    将字段列表读到字符串列表中,再判断
      

  6.   

    说到ValueFromIndex[i],Tstring在D6里有不有这个属性呀?我用D6但用上面代码提示[Error]Undeclared identifier:'ValueFromIndex'
      

  7.   

    字符串分析而已,没什么难的ReadSectionValues后
    TStringList上用Copy,Pos分离出“=”和“000”自然可以获得“aaa”具体代码?最好自己想了,要不就等那位空闲的来给你写吧http://lysoft.7u7.net
      

  8.   

    [REMOTE]
    server=ygf
    //假设ini内容为上。
    uses inifiles                                       
    IniFile: TIniFile;                                          
    function TfrmSETOperator.constring():widestring;
    var
      path:string;
      strServer:string;
    begin
      path:=ExtractFilePath(Application.ExeName); //当前应用程序路径
      path:=path+'data.ini';                      //得到(.ini)的路径。
      IniFile:=TIniFile.Create(path);             
      strServer:=inifile.ReadString('REMOTE','server','');
      showmessage(strServer);                      //显示应该为ygf 
    end;