First the Code:
procedure TfrmJob.lvServiceReportsMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Single);
var
i: Integer;
rct: TRectF;
begin
if Button = TMouseButton.mbRight then
for i := 0 to lvServiceReports.Items.Count-1 do
Begin
rct := lvServiceReports.GetItemRect(i);
if ( rct.Bottom >= Y) and (Y >= rct.Top ) then
if lvServiceReports.Items[i].Data['Image6'].IsEmpty
then lvServiceReports.Items[i].Data['Image6'] := imgEmailSelect.Bitmap
else ;//lvServiceReports.Items[i].Data['Image6'] := ??
end;
end;
I am still new to Firemonkey from VCL however, I am learning fairly quickly, so I am all ears as the saying goes.
A Dynamic Listview is full of items which can be selected and emailed. I am enabling the user to select multiple items by way of a mouse right click captured by mousedown event. When the user right-clicks an item, I display an image using a TImageObjectAppearance item in the dynamic listview. If the user right-clicks a currently selected item which has the image displayed, I want to clear the image, informing the user that the item has been unselected. I iterate through all items when selecting or unselecting, as there are not many to loop through (less than 100).
My question is how do I go about clearing an image from TImageObjectAppearance (lvServiceReports.Items[i].Data['Image6'] in the code above is the image I want cleared)
CodePudding user response:
Using Dynamic Listview you can access objects and cast them. The FMX TListview has a method that makes it easy and simple.
In your case I would use:
lvServiceReports.Items[i].Objects.FindObjectT<TListItemImage>('Image6').Bitmap := nil;
This will clear the image.
If you want to assign another image make sure to create it again:
lvServiceReports.Items[i].Objects.FindObjectT<TListItemImage>('Image6').Bitmap := TBitmap.Create;