Solved

treeview question

Posted on 2001-07-09
6
249 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
6 Comments
 
LVL 5

Accepted Solution

by:
TheNeil earned 50 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

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: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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now