Link to home
Start Free TrialLog in
Avatar of SOBKing
SOBKing

asked on

URGENT!!!! C++ Builder Question About TreeViews

my question is for C++Builder

i have a TreeView with multiple nodes.. each node has the .data property set to point to some structure with additional info about that node

now i need to know how to save that TTreeView to a file of some kind and then load it again...

and i need the .data to be saved as well so when im done loading it.. it will be there too!

please dont tell me to use the .SaveToFile property as that wont save the .data part  (unless im doing something wrong)


just incase no one know what im talking about the .data thing i will give some code

here is the code i use to add an item to the tree

//The Structure
struct TreeLeaf {
   char Name[40];
   char Description[100];
   char Pin[2];
   char Light[8];
};

//The Add Code
   TreeLeaf *data;
   TTreeNode *node;

   data = (TreeLeaf *)malloc(sizeof(TreeLeaf));

   strcpy(data->Pin, "00");
   strcpy(data->Light, "00000000");
   strcpy(data->Description, "New Item");

   node = spSkinTreeView1->Items->Add(NULL,"New Item");
   node->Data = data;
   node->Selected = true;

   Current = node;




so as you can see each node has some additional data attached to it.. which is critical to be saved along with the tree..
Avatar of Agarici
Agarici
Flag of Romania image


you can use the falowing method to save your tree:


- save the data associated with the tree nodes in file as a sequence (given by a tree traversal -- Breadth-first for example) let's call it NS (Nodes Sequence)

- for reconstructing the tree you will need to save some aditional data namely a sequence of integers (of a lenght equal to that of the sequence obtained as a result of the traversal procedure) let's call it FS (Father Sequence).
each position in FS is associated to the node on the same position in NS and contains  the position where you have the node's parent in NS.

- you will also have to save the number of nodes in your file

observation:
1.you will need a travesal procedure which will insert a TreeNode in NS only after inserting the node's parent.


I hope this idea will help you


A
Avatar of SOBKing
SOBKing

ASKER

ok cool.. that makes sence...

but i dont know hot to traverse a complex tree...

i can do a binary search tree with recursion :)


i understand how u would do the complicated one.. but just dont know the code
ASKER CERTIFIED SOLUTION
Avatar of Agarici
Agarici
Flag of Romania image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by: SOBKing

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Tinchos
EE Cleanup Volunteer