能不能给TTreeNode增加一个属性?(100分)

  • 主题发起人 主题发起人 meckyhan
  • 开始时间 开始时间
M

meckyhan

Unregistered / Unconfirmed
GUEST, unregistred user!
可以通过修改源代码加,但修改完成后,如何编译?
 
当然可以了,
但要把你修改的单元文件放在你工程文件目录中,这样
编译时,编译你修改的文件,而不是系统中的单元文件

如果把系统中的文件覆盖了,DELPHI会报错,
说版本不对,不知哪个大侠能解答一下,并
解决这个问题
 
TTreeNode 本向有一个Data 指针,既然是指针,所以足够了.
随你指向什么.
 
tag也行;
 
这个问题我昨天解决了,就是用data
下面是delphi的帮助,相信你应该能够看懂
The following code defines a record type of TMyRec and a record pointer type of PMyRec.

type
PMyRec = ^TMyRec;
TMyRec = record
FName: string;
LName: string;
end;

Assuming these types are used, the following code adds a node to TreeView1 as the last sibling of a specified node. A TMyRec record is associated with the added item. The FName and LName fields are obtained from edit boxes Edit1 and Edit2. The Index parameter is obtained from edit box Edit3. The item is added only if the Index is a valid value.

procedure TForm1.Button1Click(Sender: TObject);

var
MyRecPtr: PMyRec;
TreeViewIndex: LongInt;
begin
New(MyRecPtr);
MyRecPtr^.FName := Edit1.Text;
MyRecPtr^.LName := Edit2.Text;
TreeViewIndex := StrToInt(Edit3.Text);
with TreeView1 do
begin
if Items.Count = 0 then
Items.AddObject(nil, 'Item' + IntToStr(TreeViewIndex), MyRecPtr)
elseif (TreeViewIndex < Items.Count) and (TreeViewIndex >= 0) then
Items.AddObject(Items[TreeViewIndex], 'Item' + IntToStr(TreeViewIndex), MyRecPtr);

end;
end;

After an item containing a TMyRec record has been added, the following code retrieves the FName and LName values associated with the item and displays the values in a label.

procedure TForm1.Button2Click(Sender: TObject);

begin
Label1.Caption := PMyRec(TreeView1.Selected.Data)^.FName + ' ' +
PMyRec(TreeView1.Selected.Data)^.LName;
end;
 
用treenode的data属性,这不是一个指针吗?所以你想保存什么都可以了.
 
后退
顶部