Destruktion
Programmer
Hi, Im trying to copy the structure of a TTreeview to a popup menu, I can do this getting the caption and image of the tree nodes and adding it to the popup menu, but I cant get the parent and child relationship working.
Please see my code and help me make the changes.
Thanks
Please see my code and help me make the changes.
Code:
procedure TfrmMain.FormCreate(Sender: TObject);
begin
tvwMain.FullExpand;
end;
procedure TfrmMain.cmdRoot1AsMenuClick(Sender: TObject);
var
P: TTreeNode;
i: Integer;
MenuItem, SubItem: TMenuItem;
pt: TPoint;
begin
mnuPopup.Items.Clear;
for i:= 0 to tvwMain.Items.Count -1 do // iterate through the tree
begin
if tvwMain.Items[i].Level > 0 then // ignore highest root
begin
P:= tvwMain.Items[i];
while Assigned(P.Parent) do
begin
P:= P.Parent;
end;
if P.Text = 'Root1' then // scan Root1 of treeview only and
begin // add the nodes to the popup menu
MenuItem:= TMenuItem.Create(mnuPopup);
MenuItem.Caption:= tvwMain.Items[i].Text;
MenuItem.ImageIndex:= tvwMain.Items[i].ImageIndex;
if tvwMain.Items[i].HasChildren then
begin
//
end;
mnuPopup.Items.Add(MenuItem);
end;
end;
end;
// position and show the popup menu
pt.X:= TSpeedButton(Sender).Left + 1;
pt.Y:= TSpeedButton(Sender).Top + TSpeedButton(Sender).Height + 1;
pt:= ClientToScreen(pt);
mnuPopup.Popup(pt.X, pt.Y);
end;
procedure TfrmMain.cmdRoot2AsMenuClick(Sender: TObject);
begin
//
end;
procedure TfrmMain.cmdRoot3AsMenuClick(Sender: TObject);
begin
//
end;
procedure TfrmMain.cmdFullTreeviewAsMenuClick(Sender: TObject);
begin
//
end;
Thanks