I have a CheckBox on my form. I click on some line and it stands out. After I selected the string, its name should be transferred to the StatusBar .

  StatusBar1.Panels[0].Text := Form1.CheckListBox1.Items.Text; 

I tried this, but the whole text from the CheckBox into the panel.

  • Details in the studio - HELO WORD

2 answers 2

But it will only display the text of the last selected item (even if a lot is checked)

 procedure TForm1.CheckListBox1ClickCheck(Sender: TObject); begin StatusBar1.Panels[0].Text := CheckListBox1.Items.ValueFromIndex[CheckListBox1.ItemIndex]; end; 

To all selected output can be as follows:

 procedure TForm1.CheckListBox1ClickCheck(Sender: TObject); var i: integer; begin StatusBar1.Panels[0].Text := ''; for i := 0 to CheckListBox1.Count - 1 do begin if (CheckListBox1.Checked[i]) then StatusBar1.Panels[0].Text := StatusBar1.Panels[0].Text + ' ' + CheckListBox1.Items.ValueFromIndex[i]; end; end; 

    You need to refer to the selected item.
    To do this, use CheckListBox1.ItemIndex

     if CheckListBox1.ItemIndex <> -1 then StatusBar1.Panels[0].Text := Form1.CheckListBox1.Items[CheckListBox1.ItemIndex].Text;