Search code examples
delphitchecklistbox

TCheckListBox strange behaviour, not showing first char


So I have a CheckListBox with 6 Items :

Items.Strings = (
    'Banana'
    'Apple'
    'Pomelo'
    'Orange'
    'Peach'
    'BlueBarry')

If I want to show them then into a ShowMessage dialog, the message printed is.

'anana','pple','omelo','range','each','lueBarry'.

The procedure I use is this.

procedure TForm1.Button1Click(Sender: TObject);
var I : Integer;
begin
     for I := 0 to CheckListBox1.Items.Count - 1 do
          ShowMessage(CheckListBox1.Items.ValueFromIndex[I]);
end;

Why can't I get the first char from my Item?


Solution

  • Try to insert items in the right way like this

    procedure TForm1.Button1Click(Sender: TObject);
    begin
      CheckListBox1.Items.Add('Banana');
      CheckListBox1.Items.Add('Apple');
      CheckListBox1.Items.Add('Pomelo');
      CheckListBox1.Items.Add('Orange');
      CheckListBox1.Items.Add('Peach');
      CheckListBox1.Items.Add('BlueBarry');
    end;
    

    the result will be:

    enter image description here

    then...

    procedure TForm1.Button2Click(Sender: TObject);
    var I : Integer;
    begin
         for I := 0 to CheckListBox1.Items.Count - 1 do
              ShowMessage(CheckListBox1.Items[I]);
    
    end;