Saving Tree to a file

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
HGAutomator
Posts: 188
Joined: Thu Jul 16, 2020 5:42 pm
DBs Used: DBF

Saving Tree to a file

Post by HGAutomator »

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?
User avatar
serge_girard
Posts: 3161
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Saving Tree to a file

Post by serge_girard »

I would like to have that too!
There's nothing you can do that can't be done...
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: Saving Tree to a file

Post by edk »

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.
Tree_99.7z
(4.11 KiB) Downloaded 116 times
For exercise purposes, try to expand the export / import functions with e.g. information which nodes are expanded and which are collapsed. :mrgreen:

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
Enjoy.
User avatar
serge_girard
Posts: 3161
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Saving Tree to a file

Post by serge_girard »

Thanks !
There's nothing you can do that can't be done...
HGAutomator
Posts: 188
Joined: Thu Jul 16, 2020 5:42 pm
DBs Used: DBF

Re: Saving Tree to a file

Post by HGAutomator »

Very nice, that's a start. Thanks, edk.
User avatar
AidTIC
Posts: 117
Joined: Mon Apr 22, 2013 8:29 am
DBs Used: DBF
Contact:

Re: Saving Tree to a file

Post by AidTIC »

Sabríais si hay algún tamaño máximo para variables json?

viewtopic.php?f=24&t=6925&p=66502&hilit=json#p66502
Skydone Solutions
www.skydone.com
Post Reply