关于inifile读取的简单问题!急!在线!(50分)

  • 主题发起人 主题发起人 tt55
  • 开始时间 开始时间
T

tt55

Unregistered / Unconfirmed
GUEST, unregistred user!
我现在有一个inifile,部分内容如下:
[命令1类]
0002 = delete all
0003 = edit one
0005 = copy next
0004 = paste line
[命令2类]
0013 = find string
0007 = replace
0009 = add one
0001 = select next
我现在已知某section 中的某一项的值想找出对应的section ,请问有什么函数吗?
如果没有,能不能提供一种好的解决办法,谢谢了先!急急!在线等待!
 
懒汉办法,AHM2000和LMD TOOLS都有读ini文件的控件,直接采用或研究后化为己用.
 
能不能说的具体点
 
用AHMStoreData,怎么用自己看HELP
 
function ReadFromINI(iniCatgory,identify,ini_name:string):string;
begin
editini:=tinifile.Create(ini_name);
readfromini:=editini.Readstring(iniCatgory,identify,'');
end;
procedure Tform1.btnClick(Sender: TObject);
var
CommandString:string;
begin
CommandString:=ReadFromIni('命令1类','0002','config.ini');
end;
 
你的键名都是数字,不存在大小写问题。
如果键名有大小混合的情况,处理时可以都转成大写或小写。
以下是用函数的形式实现的。
function GetSectionNameFromKey(FileName,KeyName:string):string;
var
AppIni: TIniFile;
Sections,keys:TStrings;
i:integer;
begin
Result:='';
if (length(FileName)=0) or not(fileExists(FileName)) then
exit;
AppIni := TIniFile.Create(FileName);
Sections:=TStringList.Create;
Keys:=TStringList.Create;
AppIni.ReadSections(Sections);
for i:=0 to Sections.Count -1 do
begin
AppIni.ReadSection(sections,Keys);
if keys.IndexOf(KeyName)>=0 then
begin
Result:=sections;
break;
end;
end;
Sections.Free;
Keys.Free ;
AppIni.Free;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
showmessage(GetSectionNameFromKey('d:/temp.txt','0001'));
//'命令2类'
showmessage(GetSectionNameFromKey('d:/temp.txt','0002'));
//'命令1类'
showmessage(GetSectionNameFromKey('d:/temp.txt','xxxx'));
//''
end;
 
后退
顶部