2014-01-11 58 views
-2

我有一個名爲ListBoxPlayers的TListBox,我相信ListBoxPlayers.Items引用了TListBox中的TStrings列表。我正在嘗試使用this函數,但它似乎不起作用。有任何想法嗎?獲取Lazarus中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然而,許多項目也有在列表中。

+2

定義「沒有按似乎沒有用「。顯示你的代碼。 –

+0

它總是0.我已更新我的代碼。 – user2412643

+0

哈哈我是個白癡。忘記從一開始就刪除ListBoxPlayers.clear。謝謝! – user2412643

回答

3

它應該是完全一樣的,因爲它出現,它工作在Delphi中以同樣的方式:

NumberOfItems := ListBoxPlayers.Items.Count; 

對於循環:

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

或者

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