Solved

Drawing a tree in delphi?

Posted on 1998-06-29
3
889 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

786 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