delphilistbox

How to check if listbox is empty?


I want to do a check on a ListBox if it is empty, like:

if {Listbox.Items is empty} then
begin
  Listbox.Items.Add('Item');
end else
begin
  //do somthing else
end;

The part of the check if Listbox.Items or if Listbox are/is empty is a little hard for me. I tried to figure out a way how to do it, but I failed as I am still a beginner with Delphi. How can I implement that in Delphi XE5?


Solution

  • if listbox.items.count = 0 then
      // it's empty