Saving Treeview nodes to file, node.data and records

Please discuss general Delphi programming topics here.

Saving Treeview nodes to file, node.data and records

Postby Proto » May 9th, 2009, 10:03 am

hey gang, hope everyone is well :P

I am developing an application management program (see screenshot below)
Image

The problem I am having is to do with saving the settings or Treeview. I have googled and seen an example on about.com saving in the xml format but my xml knowledge is nil,

The goal is to beable to save the treenode to a single file along with the images. however (the big problem) i have assigned records to each node using the node.data (pointer to a record) in which contains unique information based on each node.

Code: Select all
  type
   PAppItem   = ^TAppItem;
   TAppItem  = Record
     sFileName    :String;
     sFilePath    :String;
     sCategory    :TTreeNode;
     cmdShow      :Integer;
  end;


category nodes do not have this record assigned to it but application nodes do. Is it possible to save all this data?
Proto
Member
Member
 
Posts: 1
Joined: May 9th, 2009, 10:01 am

Re: Saving Treeview nodes to file, node.data and records

Postby Kambiz » May 10th, 2009, 1:51 pm

XML is one of the most suitable formats to store hierarchical data. I do suggest to spend some times to study XML. It's very easy to learn.

Anyway, you can save your data in the format you which. Traverse TreeView nodes from root to leaves, and save data of each node that you visit. Remember, you have to assign a unique ID to each node and save ID of node and its parent besides your other data.

To load TreeView, for each node load its data, here you will have ID of node and its parent too. Use ID to locate a node with specified ID in the TreeView. Mostly the does not exists and you have to create it. Therefore you have to locate for its parent node using the parent ID to find where you have to insert the new node. This procedure is recursive.

If you couldn't figure out the code, I'll post a sample.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Re: Saving Treeview nodes to file, node.data and records

Postby Johan Theunissen » May 15th, 2009, 4:16 pm

Hi

For excellent delphi open source code for handling XML and also documentation on XML you can download XML Partner from TurboPower, You will find it on source_forge.net
Johan Theunissen
Active Member
Active Member
 
Posts: 9
Joined: November 6th, 2008, 7:26 pm


Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 5 guests

cron