一个关于TTreeView的问题。 ***** 在线等待 *****(100分)

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

coolingxyz

Unregistered / Unconfirmed
GUEST, unregistred user!
unit mystruct; //自己定义的数据结构单元

interface

uses
ComCtrls;

type
TstrMk = packed record //插槽结构
OffOn : Boolean;
Index : Integer; //插槽
Style : Integer; //设备型号
Led : Integer; //灯
end;

TstrJj = packed record //机架结构
OffOn : Boolean;
Index : Integer;
Temperature : string;
mk : Array[0..15] of TstrMk;
end;

PstrIp = ^TstrIp;
TstrIp = packed record
PIpNode : ^TTreeNode; //指向TTreeview中的第一层结点
Ip : string;
Jj : Array[0..15] of TstrJj;
end;

implementation

end.

//主程序单元中
public
PFhIp : Array of PstrIp; //TstrIp指针数组。

setlength(PFhIp,9); //初始化
For i := 0 to 8 do
begin
PFhIp := AllocMem(sizeof(TstrIp)); //分配内存空间
PFhIp^.PIpNode := nil;
PFhIp^.Ip :='192.168.3.10'+inttostr(i);
//其他赋值
end;

For i := 0 to 8 do
begin
IpNode := TTreeview1.Items.AddChildObject(Node,PFhIp^.Ip,Pointer(PFhIp));
PFhIp.PIpNode := Pointer(IpNode); //这里是想把树的结点和链表和
// 指针数组PFhIp双向关联起来
showmessage(IpNode.text); //这里能正确显示出192.168.3.10X
showmessage(PFhIp.PIpNode.Text ); //这里只能是空的一个message框
IpNode.ImageIndex := 1;
IpNode.SelectedIndex := 2;
end;

是不是我的代码哪里有问题??应该怎么写呀?
 
>>PIpNode : ^TTreeNode; //指向TTreeview中的第一层结点
改为PIpNode : TTreeNode; //指向TTreeview中的第一层结点
就可以啦
 
to chenxz
这样PIpNode就不是指针了呀??
 
那你就修改PFhIp.PIpNode := Pointer(IpNode);
PFhIp.PIpNode^ := Pointer(IpNode);

你的IpNode是怎么定义的?应该是
IpNode : TTreeNode;
 
接受答案了.
 
顶部