firemonkey

Delphi XE2 Firemonkey - Add Image to TListBox (from file)


I create a simple application, for Delphi XE2 Firemonkey I have problem to load an image to TListBoxItem! I tried, this steps:

  1. https://i.sstatic.net/b1w3d.png

  2. https://i.sstatic.net/GGyLT.png

  3. https://i.sstatic.net/1kYZn.png

  4. https://i.sstatic.net/7fuug.png

Code On Button Click:

var
 xItem : TListBoxItem;


begin
xItem := TListBoxItem.Create(nil);
xItem.Parent := ListBox1;
xItem.Height := 90; // just for test !

// code to load image file [edit1.Text] !!

xItem.Text := edit2.Text;

end;

Solution

  • Off the top of my head:

    var Image: TImage;
    
    ...
    
    Image := TImage.Create(xItem);
    Image.Parent := xItem;
    Image.Bitmap.LoadFromFile(<FileName>);
    
    
    Image.Align := TAlignLayout.alClient;  //(Not strictly necessary but guarantees images will not be positioned out of view).