Solved

Drawing a tree in delphi?

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

932 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

15 Experts available now in Live!

Get 1:1 Help Now