-2

我有一个名为 ListBoxPlayers 的 TListBox,我相信 ListBoxPlayers.Items 引用了 TListBox 内的 TStrings 列表。我正在尝试使用功能,但它似乎不起作用。有任何想法吗?

编辑:所以我试图设置 TListBox 的大小取决于它将显示多少个字符串。这是我的代码:

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无论列表中有多少项目,始终保持为 0。

4

1 回答 1

3

它应该与它看起来完全一样,并且它在 Delphi 中的工作方式相同:

NumberOfItems := ListBoxPlayers.Items.Count;

对于循环:

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

或者

for i := 0 to Pred(ListBoxPlayers.Items.Count) do
于 2014-01-11T16:03:20.440 回答