怎样给treeview的data属性赋值? (50分)

  • 主题发起人 主题发起人 chemstar
  • 开始时间 开始时间
C

chemstar

Unregistered / Unconfirmed
GUEST, unregistred user!
我定义了一个这样的结构来作为treeview.data的指针类型: 
type
indexpointer = ^Tnodedata;
Tnodedata = record
Nid: integer;
NpID: integer;
end;

然后想把两个数Nid=10,NPID=20赋给treeview.data,应怎么办?
  我用下面的代码怎么老出错?
  indexpointer(treeview1.selected.data)^.NID:=10;

请高手来看看!
 
 
1.new(indexpointer);
2.treeview1.addobject(nil,'test',indexpointer);
3.indexpointer(treeview1.items[0].data)^.NID:=10;
 
to xiaolin0522,
这三句代码要一块用吗?
第二句是怎么回事?那个nil,'text',各是什么意思?
 
var
Myindexpointer
MyNode: TTreeNode;
begin
New(Myindexpointer);
MyNode := TreeView1.AddObject(nil,'MyData',MyIndexpointer);
MyIndexpointer(MyNode.Data)^.Nid := 10;

 
function AddObject(Node: TTreeNode; const S: string; Ptr: Pointer): TTreeNode;

Description

The node is added as the last sibling of the node specified by the Node parameter. The S parameter specifies the Text property of the new node. The Ptr parameter specifies the Data property value of the new node. AddObject returns the node that has been added.

Note: The memory referenced by Ptr is not freed when the tree nodes object is freed.
 
TreeList.Items[index].Data := New(indexpointer);
with indexpointer(TreeList.Items[index].Data)^ do
begin
Nid := ;
NpID := ;
end;
 
谢谢大家,解决!
 

Similar threads

S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
911
SUNSTONE的Delphi笔记
S
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部