2013-10-28 21 views
0

我試圖從Firemonkey XE5中的Tlistbox獲取信息,但它具有關聯樣式,其中列表框中的每個項目都包含圖像,備忘錄和一些按鈕。列表框中的Firemonkey樣式 - 檢索數據

當單擊列表框樣式中的按鈕時,我可以從該項目獲取信息。

我想單獨從列表框中的備註框中獲取信息。以前,我會用下面的代碼得到了1項的文字:

NewString:=ListBox1.items[1]; 

不過,現在在列表框中每個項目都有一個以上的資料片。

如下我可以添加使用的代碼一個新的列表框項目:

var Item: TListBoxItem; 

begin 

Item := TListBoxItem.Create(nil); 

Item.Parent := ListBox1; 

Item.StyleLookup := 'PlaylistItem'; 

Item.StylesData['Memo1']:='test text'; 

但是,我怎麼看只是一個特定項目的備忘錄箱

感謝

阿曼


更新。

的解決方案是

Tempstr:=ListBox1.ItemByIndex(1).StylesData['Memo1'].AsString; 

我現在試圖找出如何獲取的圖像進行,因爲沒有一個AsImage或AsBitmap後綴。

回答

1

我勸子類TListBoxItem,然後添加屬性和方法獲取/使用FindStyleResource設置從樣式對象的數據,

class TMemoListBoxItem = class(TListBoxItem) 
protected 
    function GetMemoText: String; 
    procedure SetMemoText(const Text: String); 
published 
    property MemoText: String read GetMemoText write SetMemoText; 
end; 

function TMemoListBoxItem.GetMemoText: String; 
var O: TFMXObject; 
begin 
    O := FindStyleResource('Memo1'); 
    if O is TMemo then 
    Result := TMemo(O).Text 
    else 
    Result := ''; 
end; 

procedure TMemoListBoxItem.SetMemoText(const Text: String); 
var O: TFMXObject; 
begin 
    O := FindStyleResource('Memo1'); 
    if O is TMemo then 
    TMemo(O).Text := Text; 
end; 

而且也繼續爲其他數據。