delphi - TListBox 项目 AddObject Firemonkey 10.2
问题描述
我正在尝试 formShow 添加
ListBox1.Items.AddObject('TEST 1', TObject(1)) ;
ListBox1.Items.AddObject('TEST 2', TObject(2)) ;
但应用程序自动关闭(崩溃)。
这个例子工作正常
ListBox1.Items.Add('TEST 1');
ListBox1.Items.Add('TEST 2');
任何解决方案如何使用 Items.AddObject?
解决方案
因为FMX TListBox
我建议您改用该Tag
属性。
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
不会做的事情,或者对不同的项目有不同的类。
推荐阅读
- javascript - 如何将javascript计时器代码放在另一个javascript文件中
- laravel - 将 laravel dingo 与 laravel-modules 和缓存配置合并
- amazon-web-services - 我可以使用 REDIS 让服务器 1 中的客户端 1 与服务器 2 中的客户端 2 交谈(语音和视频聊天)吗?
- python - 通过对列数和行数进行分组来绘制时间序列图
- c# - 在 WPF XAML 中使用 MVVM 而不是 MultiValueConverter
- javascript - 如何让屏幕阅读器在 Angular 或任何单页应用程序中加载新页面时通知?
- python - python 3.7单行理解
- javascript - React - useState 仅影响最后一个属性值
- sql - 检查 postgres 表中列的唯一性
- c++ - 如何在内存中的数据缓冲区上使用常规 std::basic_istream::read、std::basic_ostream::write?