在Delphi中的TreeView中儲存多個數據
阿新 • • 發佈:2020-04-14
使用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;