2012-03-26 87 views
0

我想與FMX TListBox控件一起同時使用和器isChecked和IsSelected(無論用戶的選擇總是正確的)都被返回不正確的結果。這是一個已知的錯誤,是否有解決方法?Firemonkey TListbox中的IsChecked屬性沒有返回正確的結果?

我的測試代碼非常簡單:


var 
    i: integer; 
    lb: TListboxitem; 

for i:=0 to lbxPartners.items.Count-1 do 
begin 

    lb :=tlistboxitem(lbxPartners.Items[i]); 
    if lb=nil then continue; 

    if lb.IsChecked then 
    memo1.Lines.Add('item '+inttostr(i) +' checked') 
    else 
    memo1.Lines.Add('item '+inttostr(i)+' unchecked'); 
end; 
+0

它應該是lbxPartners.ListItems [i]。 – 2012-03-26 22:19:31

+0

邁克,感謝這一點 - 它現在的作品,但我發現,如果我想要的項目的文本,我仍然必須去.items stringlist; listitems [n] .text引發錯誤。哦,至少我現在有工作了! – user1248816 2012-03-27 16:01:27

+0

我已經爲你寫了一個完整的答案。 ListItems [n] .Text適合我。你會得到什麼錯誤?你有代碼示例嗎? – 2012-03-27 20:34:16

回答

4

TListBox.Items是一個字符串列表,主要是有這樣您就可以以同樣的方式爲VCL一個TListBox使用控制。

TListBox.ListItems是TListBoxItems這是它們由TListBox中顯示的子控件列表。

要訪問器isChecked屬性:

ListBox1.ListItems[n].IsChecked := True; 

您可以通過訪問文本兩種:

ListBox1.Items[n] := 'Hello'; 
ListBox1.ListItems[n].Text := 'World'; 

你完整的代碼是(注不需要一個施法):

var i: integer; lb: TListboxitem; 

for i:=0 to lbxPartners.items.Count-1 do begin 
    lb := lbxPartners.ListItems[i]; 
    if lb=nil then continue; 

    if lb.IsChecked then 
    memo1.Lines.Add('item '+inttostr(i) +' checked') 
    else 
    memo1.Lines.Add('item '+inttostr(i)+' unchecked'); 
end; 
+1

不應該ListBox1.Items [n] .IsChecked:= True;是ListBox1.ListItems [n] .IsChecked:= True; ? – HeartWare 2012-03-30 05:05:56

+0

是的,對不起。回答編輯。 – 2012-03-30 22:31:23

相關問題