2017-08-06 2 views
-4

LabelおよびshellExecuteに表示されたComboBoxキー値の選択に応じて、.iniファイルのセクションをComboBoxに正しく追加する方法ComboBoxに.iniファイルのセクションを正しく追加する方法

私の.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. 
+0

これで、iniから取得したデータでコンボボックスを作成しようとしていますか? –

+0

はい。キー値をそのまま使用してください。コードのように – Arsik

+0

https://stackoverflow.com/q/9338283/62576では、コンボボックス/不具合パーツの操作方法が表示されます。 –

答えて

0

あなたはShellExecuteプロシージャに誤ったパラメータを渡しています。変数AdressIniへの参照を渡す代わりに、最初のパラメータ(URL)として渡される文字列としてAdressIniを渡しています。 ComboBox1.Textは、現在選択されている項目のテキストが含まれているので、私はComboBox1.Text代わりのComboBox1.Items[ComboBox1.ItemIndex]を読んでいる

procedure TForm3.ComboBox1Select(Sender: TObject); 
var AdressIni: string; 
begin 
    Ini := TIniFile.Create('D:\Proba.ini'); 
    try 
    //Form3.Caption := INI.ReadString(ComboBox1.Items[ComboBox1.ItemIndex],'Adress', ''); 
    AdressIni := INI.ReadString(ComboBox1.Text,'Adress',''); 
    Form3.Caption := AdressIni; 
    ShellExecute(handle, 'open', PCHAR(AdressIni), nil, nil, sw_shownormal); 
    finally 
    INI.Free; 
    end 
end; 

お知らせ:ここ

は、あなたがそれを行うことができる方法です。

+0

うまくいきません。ありがとうございます – Arsik

+0

どうしたらうまくいかないのですか?私は前に投稿したコンピュータでこれをテストしたところ、うまくいきました – SilverWarior

+0

これはどうやって動作しますか? ComboBoxに.iniファイルを追加していない場合は、追加したら、WWWページの代わりにプロジェクトウィンドウが開きます。ラベルには何も表示されません – Arsik

関連する問題