delphipascallazarustlistbox

Get Length of TStrings List in Lazarus


I have a TListBox called ListBoxPlayers, and I believe ListBoxPlayers.Items references the list of TStrings inside the TListBox. I am trying to use this function but it doesn't seem to work. Any ideas?

EDIT: So I'm trying to set the size of the TListBox dependent on how many strings it is going to display. Here's my code:

procedure TForm3.edtSearchChange(Sender: TObject);
begin
  ListBoxPlayers.Clear;
  if Length(edtSearch.text) > 0 then
     begin
        setSizeListBox((ListBoxPlayers.Items.Count));
        ListBoxPlayers.Visible:=true;
        dynamicSearch(edtSearch.Text)
     end
  else
     ListBoxPlayers.Visible:=false;
end;  

ListBoxPlayers.Items.Count always stays at 0 however many items there are in the list.


Solution

  • It should be the exact same as it appears, and the same way it works in Delphi:

    NumberOfItems := ListBoxPlayers.Items.Count;
    

    For looping:

    for i := 0 to ListBoxPlayers.Items.Count - 1 do
    

    Or

    for i := 0 to Pred(ListBoxPlayers.Items.Count) do