?
Solved

treeview question

Posted on 2001-07-09
6
Medium Priority
?
284 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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 brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

777 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