Hi,
I've looked at all the Tree Samples, and the only SaveAs option is a bitmap. Are there are any existing snippets for saving a tree to xml or json, or to a database?
Saving Tree to a file
Moderator: Rathinagiri
- serge_girard
- Posts: 3166
- Joined: Sun Nov 25, 2012 2:44 pm
- DBs Used: 1 MySQL - MariaDB
2 DBF - Location: Belgium
- Contact:
Re: Saving Tree to a file
I would like to have that too!
There's nothing you can do that can't be done...
Re: Saving Tree to a file
I don't think there is a ready solution for exporting / importing trees, but you can easily build your own solutions.
Below I present the code that allows you to write and read the tree structure to a file in json format.
It is not a ready-made universal tool and it will certainly not work in all applications, but it shows how the tree structure export / import operation can be quite easily accomplished.
I chose the json format so that tasks would be performed on arrays, but you can successfully (with a little modification) use a DBF file. For exercise purposes, try to expand the export / import functions with e.g. information which nodes are expanded and which are collapsed.
By the way, I found a strange bug in the DeleteAllItems method. It has something to do with the use of the GetFile / PutFile function, but I can't find the reason. You can observe this error by following these steps:
For the GetFile function:
1. Click the "Delete All / Add Test" button
2. Click the "Load Tree Stru" button
3. Cancel loading the file.
4. Click the "Delete All Items" button
For the PutFile function:
1. Click the "Delete All / Add Test" button
2. Click the "Save Tree Stru" button
3. Cancel saving the file.
4. Click the "Delete All Items" button
For this reason, in my tree structure import function, I used this snippet of code instead of the DeleteAllItems method:
Enjoy.
Below I present the code that allows you to write and read the tree structure to a file in json format.
It is not a ready-made universal tool and it will certainly not work in all applications, but it shows how the tree structure export / import operation can be quite easily accomplished.
I chose the json format so that tasks would be performed on arrays, but you can successfully (with a little modification) use a DBF file. For exercise purposes, try to expand the export / import functions with e.g. information which nodes are expanded and which are collapsed.
By the way, I found a strange bug in the DeleteAllItems method. It has something to do with the use of the GetFile / PutFile function, but I can't find the reason. You can observe this error by following these steps:
For the GetFile function:
1. Click the "Delete All / Add Test" button
2. Click the "Load Tree Stru" button
3. Cancel loading the file.
4. Click the "Delete All Items" button
For the PutFile function:
1. Click the "Delete All / Add Test" button
2. Click the "Save Tree Stru" button
3. Cancel saving the file.
4. Click the "Delete All Items" button
For this reason, in my tree structure import function, I used this snippet of code instead of the DeleteAllItems method:
Code: Select all
Do While GetProperty ( cFormName, cTreeName, "ItemCount" ) > 0
DO Events
DoMethod( cFormName, cTreeName, "DeleteItem", GetProperty ( cFormName, cTreeName, "ItemCount" ) )
Enddo
- serge_girard
- Posts: 3166
- Joined: Sun Nov 25, 2012 2:44 pm
- DBs Used: 1 MySQL - MariaDB
2 DBF - Location: Belgium
- Contact:
-
- Posts: 188
- Joined: Thu Jul 16, 2020 5:42 pm
- DBs Used: DBF
Re: Saving Tree to a file
Very nice, that's a start. Thanks, edk.
Re: Saving Tree to a file
Sabríais si hay algún tamaño máximo para variables json?
viewtopic.php?f=24&t=6925&p=66502&hilit=json#p66502
viewtopic.php?f=24&t=6925&p=66502&hilit=json#p66502
Skydone Solutions
www.skydone.com
www.skydone.com