在Delphi中的TreeView中保存多个数据
使用Delphi几年后,居然不知道还可以这么用,惭愧呀
type PMyRec = ^TMyRec; TMyRec = record FName: string; LName: string; end; 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) else if (TreeViewIndex < Items.Count) and (TreeViewIndex >= 0) then Items.AddObject(Items[TreeViewIndex], 'Item' + IntToStr(TreeViewIndex), MyRecPtr); end; end; procedure TForm1.Button2Click(Sender: TObject); begin Label1.Caption := PMyRec(TreeView1.Selected.Data)^.FName + ' ' + PMyRec(TreeView1.Selected.Data)^.LName; end;
好的代码像粥一样,都是用时间熬出来的