TListBox项目AddObject Firemonkey 10.2 [英] TListBox Items AddObject Firemonkey 10.2

查看:94
本文介绍了TListBox项目AddObject Firemonkey 10.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用formShow add

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).

这个例子很好用

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

任何解决方案如何使用Items.AddObject?

Any solution how use Items.AddObject?

推荐答案

对于FMX TListBox,建议您改用Tag属性.

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

这只是一个伪代码,但是您知道了.它还使您能够从TListBoxItem派生一个类,并使它执行正常的TListBoxItem不会执行的操作或为不同的项目提供不同的类.

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.

这篇关于TListBox项目AddObject Firemonkey 10.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆