问题描述
我不确定如何将数据分配给VirtualStringTree中的节点.我需要在树控件的InitNode事件中将指向记录对象的指针分配给Node的Data属性.但是,我遇到了需要指针类型"的编译时错误.
I am not sure how to assign data to a node in a VirtualStringTree. I'm need to assign a pointer to a record object to the Node's Data property in the tree control's InitNode event. However I'm getting a 'Pointer type required' compile-time error.
是TObject的后代的东西.当您不使用对象时,请勿使用TObjectList.如果您使用的Delphi版本早于2009,请使用TList并将 pointers 存储到TDiagData:Furthermore, you're confused about your data types. You say FDiagDataList is a TObjectList, but you're clearly storing something in it that isn't a descendant of TObject. When you're not using objects, don't use TObjectList. If you're using a version of Delphi earlier than 2009, then use TList and store pointers to TDiagData:
NodeData^ := PDiagData(FDiagDataList[c])^;如果您使用的是Delphi 2009或更高版本,请使用TList<TDiagData>,然后删除强制类型转换:
If you're using Delphi 2009 or later, then use TList<TDiagData>, and then get rid of the type cast:
NodeData^ := FDiagDataList[c];无论哪种方式,如果每个事件处理程序以相同的方式启动,并且调用GetNodeData来获取指向当前节点的类型安全指针,则可能会发现更易于管理.数据.
Either way, you'll probably find things easier to manage if every event handler starts out the same way, with a call to GetNodeData to fetch the type-safe pointer to the current node's data.
这篇关于如何在InitNode事件中将数据分配给VirtualStringTree的节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!