本地文件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 ,如何做?先谢谢了!
[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 ,如何做?先谢谢了!
能具体点吗?
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;
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;
将字段列表读到字符串列表中,再判断
TStringList上用Copy,Pos分离出“=”和“000”自然可以获得“aaa”具体代码?最好自己想了,要不就等那位空闲的来给你写吧http://lysoft.7u7.net
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;