TListBox的item项的Data关联及调用
来源:互联网 发布:mac队武器纪念馆 编辑:程序博客网 时间:2024/05/15 02:14
I have one record type. I want to add the variable of that record type in TListbox and retrieve it on click event of TListbox. Is it possible? If yes then how?
I added it using
lstbox.AddItem(data,myrec);
It shows error of incompatible types. data is string and myrec is variable of MyRecord which I have created.
For adding:
New(fptr1);ZeroMemory(fptr1,sizeof(fptr1^));fptr1^ := fptr^;lstboxLeft.AddItem(path,TObject(fptr1));
For retrieve:
fptr := PData(lstboxLeft.Items[lstboxLeft.ItemIndex]);
ANSWER:
AddItem takes a TObject as the second parameter and a record is not an object. You could either make your record a TObject instead (usually the best solution) or cast the record to an object.
Here is a working example using records:
type PMyRec = ^TMyRec; TMyRec = record I : integer; end;procedure TForm1.FormCreate(Sender: TObject);var P : PMyRec;begin New(P); P.I := 42; ListBox1.AddItem('One',TObject(P));end;procedure TForm1.FormDestroy(Sender: TObject);var I : integer;begin //Free memory for I := 0 to ListBox1.Items.Count - 1 do Dispose(PMyRec(ListBox1.Items.Objects[I]));end;procedure TForm1.ListBox1Click(Sender: TObject);var P : PMyRec;begin P := PMyRec(ListBox1.Items.Objects[ ListBox1.ItemIndex ]); ShowMessage( IntToStr(P.I) );end;
0 0
- TListBox的item项的Data关联及调用
- TListBox的Item改变高度
- TListbox中的item根据内容显示不同颜色的方法
- Ttreeview和TlistBox的几个常用属性与方法
- DELPHI TListBox (TStrings类)删除空行的方法
- 给TListBox 增加水平滚动条的方法
- spring data jpa save 方法中,不能自动关联,新建的关联项
- Delphi TListBox选中项操作
- 改变listview的item项的颜色、自定义expandlistview的group、item的颜色,改变、调用android.R.layout参数
- “System.Data.DataRow”并不包含“Item”的定义
- “System.Data.DataRow”并不包含“Item”的定义
- 小程序模板中的data里面的...item是什么意思
- Adapter item 中设置监听和抽象方法及Activity中调用Adapter中监听的方法,获取item中postion
- 使用<data android: 建立和activity的关联
- UserControl调用Umbraco的Data Types
- Item 5 编译器自动生成和调用的函数
- ListView的item点击无响应,onItemClick()没被调用
- hibernate复合主键及关联的实现
- Java——匿名内部类精讲
- 如何启动/停止/重启MySQL + 进入MYSQL
- imageWithName与imageWithContentsOfFile
- LeetCode 022 Generate Parentheses
- 右击显示菜单
- TListBox的item项的Data关联及调用
- JAVA中关于时间的转换
- 谷歌发布2015年度搜索排行榜
- Linux gmp类库的简单使用(一)
- 第一個C程式
- c++ note--unix程序日志实现
- 数据结构上机实验-希尔排序,快速排序,堆排序
- 编辑内容
- 在工作组环境下配置CA并应用到Web服务器和客户端