Adriaan
Adriaan

Reputation: 806

FMX Loading image from resources onto a listview object causes access violation

I have a TListview with a Dynamic Appearance. I added a image object and now I'm trying to load an image from the resources onto this imageobject but I keep getting a access violation.

My Code:

procedure TfrmMain.btnAddPlayerClick(Sender: TObject);
var
  ListItem: TListViewItem;
  imgBanned: TListItemImage;
  InStream: TResourceStream;
begin
  InStream := TResourceStream.Create(HInstance, 'banned', RT_RCDATA);
  lvPlayers.BeginUpdate;
  try
    ListItem := lvPlayers.Items.Add;
    imgBanned := ListItem.Objects.FindObjectT<TListItemImage>('imgBanned');
    imgBanned.Bitmap.LoadFromStream(InStream);
  finally
    lvPlayers.EndUpdate;
    InStream.Free;
  end;
end;

EDIT: After Debugging I get the following but I have no idea what it means. I see that it has something to do with GetFieldAddress but I'm unsure as to what this is

enter image description here enter image description here

Upvotes: 1

Views: 2333

Answers (1)

SilverWarior
SilverWarior

Reputation: 8386

You need to create your own bitmap and then set TImageListItem.Bitmap to reference it in order to load images programmatically.

Check the documentation on TListViewItem.Bitmap property on how to handle this properly http://docwiki.embarcadero.com/Libraries/Tokyo/en/FMX.ListView.Appearances.TListViewItem.Bitmap

Upvotes: 2

Related Questions