Solved

Drawing a tree in delphi?

Posted on 1998-06-29
3
883 Views
Last Modified: 2012-06-27
I need to draw a tree using delphi, I guess the best component available is Toutline??

Anyhow, I can draw nodes on this tree easily using
Outline1.Insert(0,'a node');

But I can't seem to figure out how to draw a children for that node...

ie how do i draw this (help me with the missing code)

-a node
-another node
 -child of another node
  -child of the child

Outline1.Insert(0,'a node');
Outline1.Insert(1,'another node');
???
???

Also, how can I remove nodes/children..

This is probably a very easy question... so thanks for taking the time to answer it...

By the way, if there is another component that may be better suited for drawing trees (I need a tree of text not files) please let me know...

0
Comment
Question by:rafyt
3 Comments
 
LVL 2

Accepted Solution

by:
kjteng earned 50 total points
ID: 1356554
Each item in the outline tree has a reference number, you must refer to these number when you want to add child to a specific node or when you want to delete an item.

You can get the index number for a selected item from the outline.selectedItem property

Please read the delphi help for more details. For simple operation, I don't think you need a third party component. Yes there are some ready made components doing such things like auto drag and drop, construct tree from database info etc. Check delphiSuperPage.


Example:
procedure TForm1.BitBtn2Click(Sender: TObject);
var i: longint;
begin
  with outline1 do begin
{  -a node}
   add( 0, 'a node');
{  -another node}
   i:= add( 1, 'another node');
{    -child of another node}
   i:= addChild( i, 'child of another node');
{    -child of another node}
   i:= addChild( i, 'child of child');
   fullExpand
 end;
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
{ remove nodes/children}
  with outline1 do
    delete( selectedItem);
end;
0
 
LVL 3

Expert Comment

by:vladika
ID: 1356555
Are you use Delphi 1?

0
 

Author Comment

by:rafyt
ID: 1356556
No I'm using Delphi 3... and I just found TtreeView (much better component to use!), and that's pretty well documented, so I answered my own questions...Thanks anyways
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
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 gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

758 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

21 Experts available now in Live!

Get 1:1 Help Now