Link to home
Start Free TrialLog in
Avatar of SOBKing
SOBKing

asked on

How To Save A TreeView To A File

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 kretzschmar
kretzschmar
Flag of Germany image

go to q

https://www.experts-exchange.com/questions/10120892/saving-treeview-data-nodes-to-file.html

you may find there some solutions, how this could be done

meikl ;-)
Avatar of SOBKing
SOBKing

ASKER

ok thanks i will look into that!

one thing i was thinking of is..

1st.. just saving the tree with the .save to file...

then after thats saved.. run thru the tree.. and for each node write the .data to a file

then when opening it...

open the ree with the loadfromfile...

then after its loaded.. run thru the tree backwards and set the .data property from that file..


the only problem with that is i dont know how to traverse a complicated tree... i know how to do a birnar tree with recursion..
If you traverse it root - left node - right node, save to file and restore in same manner then it will remain same.
For complex tree - if there is one root with 3 childs - process root, first child, second child, third child...
That is the way.

Bojidar Alexandrov
Avatar of SOBKing

ASKER

ya i understand the theory kinda.. thats what we doing in classes right now.. its the code i have no idea..

i dont understand enough about to do that...

if someone could give me some code to lets say traverse a tree and add the node->text property to a memo that would be awsome! and would get the points..  :)

oh please try to give in c++ builder. but if all u know is delphi.. i may be able to figure it out

thanks
Avatar of SOBKing

ASKER

ya i understand the theory kinda.. thats what we doing in classes right now.. its the code i have no idea..

i dont understand enough about to do that...

if someone could give me some code to lets say traverse a tree and add the node->text property to a memo that would be awsome! and would get the points..  :)

oh please try to give in c++ builder. but if all u know is delphi.. i may be able to figure it out

thanks
Avatar of SOBKing

ASKER

ya i understand the theory kinda.. thats what we doing in classes right now.. its the code i have no idea..

i dont understand enough about to do that...

if someone could give me some code to lets say traverse a tree and add the node->text property to a memo that would be awsome! and would get the points..  :)

oh please try to give in c++ builder. but if all u know is delphi.. i may be able to figure it out

thanks
Avatar of SOBKing

ASKER

ya i understand the theory kinda.. thats what we doing in classes right now.. its the code i have no idea..

i dont understand enough about to do that...

if someone could give me some code to lets say traverse a tree and add the node->text property to a memo that would be awsome! and would get the points..  :)

oh please try to give in c++ builder. but if all u know is delphi.. i may be able to figure it out

thanks
please release the submit button :-))

i advice you to read the link i gave first

meikl ;-)
Avatar of SOBKing

ASKER

i thinkt he stuf in the other post is wayyyyy over my head...

lol i guess i pressed it one too many times  hah
ASKER CERTIFIED SOLUTION
Avatar of mocarts
mocarts

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