Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
Member Area
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Become a Member
-Why sign up!
-Chat Online!
-Indexes NEW!!
-Build your resume
-Find a job
-Post a job
-Resume Search
-Link to us
Visit Embarcadero
Embarcadero Community
How to use a TTreeView to list all available reports in a program Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
Delphi 2.x
User Rating
No Votes
# Votes
DSP, Administrator
Reference URL:
			Author: Tomas Rutkauskas

I am trying to use the TTreeView to list all the available reports in my 
application. I would like to click on a specific treenode and then click an button 
to print a specific report. I don't know what property to use or how can I go about 
getting the results.


Solve 1:

There are a few ways to do this. The way I usually do this is to allocate memory 
for the report name and then add this as a pointer to the node. You can then 
dereference the pointer to get the info back. Here's an example of attaching 
information from a database.

1   if wwTable5.RecordCount > 0 then
2   begin
3     TreeNode := Items.AddChildObject(CurrentPatient, 'Treatments', nil);
4     TreeNode.ImageIndex := 5;
5     TreeNode.SelectedIndex := 5;
6     wwTable5.First;
7     while not wwTable5.EOF do
8     begin
9       New(NodeRecord);
10      NodeRecord^.RecType := Treatment;
11      NodeRecord^.RecInfo := wwTable5Number.AsInteger;
12      Items.AddChildObject(TeeNode, 'Course: ' + wwTable5CourseNumber.AsString,
13        NodeRecord);
14      wwTable5.Next;
15    end;
16  end;

I'm allocating a record, filling it with info from the database and then adding the 
node. You can also cast an integer to a pointer and add it as the object pointer. 
You can then cast it back to an integer and retrieve the information associated 
with the node.

Here's an example of getting the info back out of the node:

17  SelectedNode := SelectedNode.GetFirstChild;
18  while SelectedNode <> nil do
19  begin
20    if PNodeType(^.RecInfo = FindPatient then
21      break;
22    SelectedNode := SelectedNode.GetNextSibling;
23  end;

Solve 2:

If you have a two level tree (node -> subnodes(your_reports)). To determine what 
item is selected use property TTreeView.Selected:

24  procedure TForm1.PrintButtonClick(Sender: TObject);
25  var
26    SelectedNode: TTreeNode;
27    i: integer;
28  begin
29    SelectedNode := TTreeView1.Selected;
30    for i := 0 to SelectedNode.Count - 1
31    begin
32      if SelectedNode.Item[i].Selected then
33        MyPrintReport_procedure(Item[i].Text);
34    end;
35  end;

Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10


Share this page
Download from Google

Copyright © Mendozi Enterprises LLC