1

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)

Ken White
  • 123,280
  • 14
  • 225
  • 444
Shane
  • 39
  • 1
  • 4
  • Is `imgEmailSelect` the TImageObjectAppearance you refer to? [This may be a similar snippet in C++](https://stackoverflow.com/questions/39720898/tlistview-dynamicappearance-with-timageobjectappearance-will-not-view-image-when) – Jimmy Smith Apr 27 '22 at 19:46
  • 1
    Hi Jimmy, Yes imgEmailSelect is the image I want cleared from lvServiceReports.Items[i].Data['Image6'] in the code – Shane Apr 27 '22 at 20:01
  • Ah I believe you have to Free the bitmap as referenced here https://stackoverflow.com/questions/65055577/clearing-dynamic-fmx-listview-bitmaps-from-memory]. This may work `lvServiceReports.Items[i].Data['Image6'].Free()` – Jimmy Smith Apr 27 '22 at 20:15
  • Thanks Jimmy, but that is not the answer after checking it out in the IDE. Thanks for helping. – Shane Apr 28 '22 at 05:20
  • No problem. I figured the Free() function was doing the same as assigning it to nil, but I'm pretty new to Delphi's way of doing this. – Jimmy Smith Apr 28 '22 at 14:24

1 Answers1

0

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;
Adriaan
  • 806
  • 7
  • 24