0

I'm try on formShow add

ListBox1.Items.AddObject('TEST 1', TObject(1)) ;
ListBox1.Items.AddObject('TEST 2', TObject(2)) ;

but app automatically close (crash).

This example work fine

ListBox1.Items.Add('TEST 1');
ListBox1.Items.Add('TEST 2');

Any solution how use Items.AddObject?

Pointer
  • 2,123
  • 3
  • 32
  • 59

1 Answers1

3

For FMX TListBox I suggest you use the Tag property instead.

aItem: TListBoxItem;
begin
   aItem := TListBoxItem.Create(Self);
   aItem.Text := 'TEST 1';
   aItem.Tag := 1;
   aItem.Parent := ListBox1;

   aItem := TListBoxItem.Create(Self);
   aItem.Text := 'TEST 2';
   aItem.Tag := 2;
   aItem.Parent := ListBox1;
end

This is just a pseudo-code, but you get the idea. It also gives you the ability to derive a class from TListBoxItem and make it do something that normal TListBoxItem will not do or have different class for different items.

MartynA
  • 30,454
  • 4
  • 32
  • 73
Sam
  • 2,473
  • 3
  • 18
  • 29