【发布时间】:2018-01-13 23:49:24
【问题描述】:
如何正确地将.ini文件的各个部分添加到ComboBox中,根据在ComboBox中选择的键值显示在Label和shell中执行打开选中的网页
我的 .ini 文件
[Google]
Adress=https://www.google.co.uk
Description=Example description1
[Ask]
Adress=http://www.ask.com
Description=Example description2
[Bing]
Adress=https://www.bing.com
Description=Example description3
我的代码:
var
Form1: TForm1;
INI: TIniFile;
implementation
procedure TForm1.Button4Click(Sender: TObject);
begin
INI := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'setup.ini');
try
INI.ReadSections(ComboBox1.Items);
finally
INI.Free;
end;
end;
procedure TForm1.ComboBox1Change(Sender: TObject);
var
AdressIni:string;
begin
AdressIni := INI.ReadString(ComboBox1.Items[ComboBox1.ItemIndex],'Adress', '');
Label1.Caption := INI.ReadString(ComboBox1.Items[ComboBox1.ItemIndex],'Description', '');
ShellExecute(handle, 'open', 'AdressIni', nil, nil, sw_shownormal);
end;
end.
【问题讨论】:
-
所以您正尝试使用从 ini 中获取的数据填充组合框?
-
是的。并继续使用键值,就像代码中一样
-
stackoverflow.com/q/9338283/62576 将向您展示如何使用组合框/inifile 部分。