Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6726995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:59:42+00:00 2026-05-26T09:59:42+00:00

I have a heirarchy of data that is displayed in a VirtualStringTree. I use

  • 0

I have a heirarchy of data that is displayed in a VirtualStringTree. I use this heirarchy multiple times in my application with slight modifications to the way the tree is drawn/displayed. My method currently utilizes the AddChild() procedure for adding nodes an d as such i have multiple copies of the data when the application is run.

I would now like to consolidate these trees and have a ‘master’ tree which points to the actual data, but then have the ‘slave’ trees point to the SAME data.

I am a little unsure of if/how this can be acheived. I would think i could simply load the master tree and populate its NodeData with pointers to where the data i being held, and then for all the slave trees, simply store the same pointer in their nodedata.

However im not having much luck.

My current code looks like:

//Initialize the NodeDataSize
procedure TForm1.FormCreate(Sender: TObject);
begin
     TreeMasterComponents.NodeDataSize := SizeOf(rMasterComponent);
     VST.NodeDataSize := SizeOf(Pointer);
end;

Procedure to copy the master tree to slave trees

procedure TForm1.LoadSlaveTree(ATree: TVirtualStringTree);
var Node : PVirtualNode;

procedure RecursiveCopy(SrcPNode,SrcTNode : PVirtualNode; ATree : TVirtualStringTree);
var SrcNode, TargetNode : PVirtualNode;
SrcData : PMasterComponent;
begin
     SrcNode := TreeMasterComponents.GetFirstChild(SrcPNode);
     while Assigned(SrcNode) do
     begin
          SrcData := TreeMasterComponents.GetNodeData(SrcNode);
          TargetNode := ATree.AddChild(SrcTNode,SrcData);
          RecursiveCopy(SrcNode,TargetNode,ATree);
          SrcNode := SrcNode.NextSibling;
     end;
end;

begin
     ATree.BeginUpdate;
     ATree.Clear;
     Node := TreeMasterComponents.GetFirst(true);
     while Assigned(Node) do
     begin
         RecursiveCopy(Node,nil,ATree);
         Node := Node.NextSibling;
     end;
     ATree.EndUpdate;
end;

Procedure for slave tree to getCellText

procedure TForm1.SlaveGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
  Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
var Data : PMasterComponent;
begin
     Data := Sender.GetNodeData(Node);
     Case column of
     0:CellText := Data^.ComponentCode;
     1:CellText := Data^.FullLocation;
     end;
end;

At the moment, the nodes are added in the correct heirarchy, however there is no text appearing for the slave trees. Any help would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:59:43+00:00Added an answer on May 26, 2026 at 9:59 am

    Ok so i beleive i have found a solution:

    The trick was to create a new record to store the Pointer to the original data:

    type PRefMasterComponent = ^RefMasterComponent;
      RefMasterComponent = packed record
         PMCData : PMasterComponent;
    end;
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
         TreeMasterComponents.NodeDataSize := SizeOf(rMasterComponent);
         VST.NodeDataSize := SizeOf(RefMasterComponent);
    end;
    

    Now the Copy code looks like:

    procedure TForm1.LoadTree(ATree: TVirtualStringTree);
    var Node,TargetNode : PVirtualNode;
    SrcData : PMasterComponent;
    Data : PRefMasterComponent;
    
    procedure RecursiveCopy(SrcPNode, TargetPNode : PVirtualNode; ATree : TVirtualStringTree);
    var Node, TargetNode : PVirtualNode;
    SrcData : PMasterComponent;
    Data : PRefMasterComponent;
    begin
         Node := TreeMasterComponents.GetFirstChild(SrcPNode);
         while Assigned(Node) do
         begin
              SrcData := TreeMasterComponents.GetNodeData(Node);
              TargetNode := ATree.AddChild(TargetPNode);
              Data := ATree.GetNodeData(TargetNode);
              Data.PMCData := SrcData;
              RecursiveCopy(Node,TargetNode,ATree);
              Node := Node.NextSibling;
         end;
    end;
    
    begin
         ATree.BeginUpdate;
         ATree.Clear;
         Node := TreeMasterComponents.GetFirst(true);
         while Assigned(Node) do
         begin
              SrcData := TreeMasterComponents.GetNodeData(Node);
              TargetNode := ATree.AddChild(nil);
              Data := ATree.GetNodeData(TargetNode);
              Data.PMCData := SrcData;
              RecursiveCopy(Node,TargetNode,ATree);
              Node := Node.NextSibling;
         end;
         ATree.EndUpdate;
    end;
    

    and the OnGetText:

    procedure TForm1.vstGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
      Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
    var Data : PRefMasterComponent;
    RefData : PMasterComponent;
    begin
         Data := Sender.GetNodeData(Node);
         RefData := Data.PMCData;
         Case column of
         0:CellText := RefData.ComponentCode;
         1:CellText := RefData.FullLocation;
         end;
    end;
    

    Now if i change data in one tree all i have to do is call VST.Invalidate and the changes are reflected in the other tree.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm designing an application that will use Oracle , and we have this department
I have a non document-based Core Data application. There's an NSTreeController that manages a
I have some data that I want to present in a FlowDocument . This
I have a data structure that looks like this: public class Node { public
I have a set of data that models a hierarchy of categories. A root
I have a Notes table with a uniqueidentifier column that I use as a
I have a requirement for a Tree grid or Tree list control. This is
I have a data hierarchy that I currently display in a treeview. I was
I have defined a pyparsing rule to parse this text into a syntax-tree... TEXT
I have a heirarchy of classes that get initialized from a database. I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.