Search code examples
delphidelphi-xe

Checklistbox adding items


enter image description here

Any know what will be the problem? I want to add Items to checklistbox but nothing happens... Items are CollectionItems in a Table Collection. Tables has a Name property

  procedure TForm1.FormShow(Sender: TObject);
  var

  DisplayName: string;
  c :integer;
  begin



 for C := 0 to Compname.Tables.Count - 1 do
  with cxCheckListBox1.Items.Add do
  begin
  DisplayName := Compname.Tables.Items[C].TableName;
  Tag := C;
end;

end;

Thanks!


Solution

  • DisplayName is a local variable that is otherwise not used. You should be setting the Text property of the new item.

    I recommend that you stop using with. If you had not done so you would have written code like this:

    Item := cxCheckListBox1.Items.Add;
    Item.DisplayName := ...;
    

    The compiler could have rejected that code. As it was, using with just cluttered your scope. Please stop using it.