?
Solved

treeview question

Posted on 2001-07-09
6
Medium Priority
?
291 Views
Last Modified: 2010-04-06
Ok, I've got a treeview containing a list of web pages. They are divided in categories (folders), like sports, arts, etc. A node representing a web page may show something like "Yahoo". However, as you can imagine when you double click on this node I want my program to open IE and go to "http://www.yahoo.com". So, here is where my problem starts, because I don't know how to save this "extra" information. The treeview control let's you manage this extra info with the data property. However, as this property is just a pointer, when I close my program and start it again, all this info is lost. There must be a way (or some control) to save this info to a file. (Note: The treeview control SaveToFile method is not useful here, because it just saves the nodes captions. It doesn't even save the ImageIndex, StateIndex properties of each node).
I believe Lishcke released a control called "VirtualStringList" which included this in the "features" page before download. But, the help file is just INCOMPLETE. So, if anyone there can tell me how to save my own data to a file, so that next time my program opens this file is loaded.

thanks.
0
Comment
Question by:pin_plunder
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 5

Accepted Solution

by:
TheNeil earned 100 total points
ID: 6265196
Why not simply iterate through the items in the tree and then save their (net) addresses and complete paths out to a text file? When you read them back in you could scan for the appropritae path and assign the (net) address back to the node.

As an algorithm it'd be a case of doing this:

Open file
Output node count
FOR i := 1 TO no items in tree
DO
  Generate path to node (from the root)
  Save path and address to file
Close file

And for reading:

Build tree
Open file
Read node count
FOR i := 1 TO node count
DO
  Read path
  Read address
  Find node on the tree
  Assign the address to the node
Close File

I apologise for the algorithms (rather than code) but as I don't know how you're storing your data then I can't submit any. I also apologise for using node paths BUT (and this is important) node indexes can change (depending on what order they're created in) and I'm assuming that the tree could potentially change (if it doesn't then you can forget about node paths and just iterate straight through the tree)

Hope this helps (even if it's only a tiny bit)

The Neil =:)

 
0
 
LVL 3

Expert Comment

by:lmikle
ID: 6265307
Try to use a Data property (type - pointer) of TTreNode to save extra info.

short example

type
 PMyData = ^TMyData;
 TMyData = Record
  URL : String;
  // Other fielsa skiped...
  ...
 end;

...

 var
  Dta : PMyData;
  Node : TTreeNode;

// nodes creating
 for I := 0 to LinkList.items.Count-1 Do
 begin
  // Parse some list, retrive info and create node (skipped)
  // Node  - is a pointer to created node (TTreeNode)
  New(Dta);
  Dta^.URL := LinkList.Items[i]; // Or another var that contain an url
  Node.Data := Dta;
  // Don't dispose Dta here!!!
 end;

// start browser - for example on Dblclick
procedure TreeView1DblClick(...)
var
 URL : String;
begin
 if TreeView1.selected= Nil Then exit;
 if TreeView1.selected.Data=Nil Then exit;
 URL := TMyData(TreeView1.selected.Data^).URL;
 ShellExecute(0,Nil,PChar(URL),Nil,Nil,SW_SHOWNOACTIVATE);
end;
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6265350
if you use lischke's virtualtree,
then it provides a good streaming ability,
also for the datas

just save it to a stream (filestream) and reload if needed
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:pin_plunder
ID: 6267018
Imikle, I'm sorry but it seems you really didn't understand what happens. Using .Data property is fine, but what happens if you close the program and open it again? Those pointers will point to something else. So, I need to save that "pointed data" to some file so that next time I open my program this file loads.

kretzschmar, it would be great if you give me some code, because I tried some and didn't seem to work.

theneil, although your answer is the most "complicated" that's exactly what I was trying to do. However, you gave me some good advice because I was using absolute indexes to refer to nodes and that was causing problems.

I would prefer kretzschmar to answer first, because I really want to do this with Lischke's control.

thanks all.
0
 
LVL 5

Expert Comment

by:Tom Knowlton
ID: 6267171
Are you building the TreeView from a data structure?

The best way is to load the information into a data structure, then build the tree from that.  This seperates the GUI from the data.

Did I miss something?
0
 
LVL 3

Expert Comment

by:rondi
ID: 6298573
A while back, I succeeded in doing the same thing
with a TListView where each list item had to have
some persisted custom data associated with it.

How ? I created a new ListView control descending from the
VCL's TListView and overrode the component streaming methods that use TReader, TWriter etc.

If you like, I can post some code modified for a
TTreeView, but you've gotta UP the points!!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question