Reputation: 1
I'm trying to get information from a Tlistbox in Firemonkey XE5 but it has an associated style where each item in the listbox includes an image, a memo and some buttons.
When clicking on the button inside the listbox style, I can get information from that item.
I want to get information from a the memo box in the listbox separately. Previously, I would have got the text from item 1 by using the following code:
NewString:=ListBox1.items[1];
However, now each item in the listbox has more than one piece of information.
I can add a new Listbox item using the code as follows:
var Item: TListBoxItem;
begin
Item := TListBoxItem.Create(nil);
Item.Parent := ListBox1;
Item.StyleLookup := 'PlaylistItem';
Item.StylesData['Memo1']:='test text';
But, how do I read just the memo box of a particular item
Thanks
Aman
Update.
The solution is
Tempstr:=ListBox1.ItemByIndex(1).StylesData['Memo1'].AsString;
I'm now trying to work out how to get an image out as there isn't a AsImage or AsBitmap suffix.
Upvotes: 0
Views: 1617
Reputation: 4211
I would advise subclassing TListBoxItem, then adding properties and methods to get/set the data from the style objects using 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;
And continue likewise for your other data.
Upvotes: 1