Solved

TreeView in Delphi 5

Posted on 2001-06-28
14
496 Views
Last Modified: 2011-09-20
I got a problem when I was using TreeView in Delphi5 application.
The Tree was loaded automatically when FormShow
If I didn't click the tree, everything OK
If I click the tree, then the Node.getNextSibling and Node.getFirstChild could no work sometimes(error message).

Anyone has this experience before? how can I solve it?

ysimon
0
Comment
Question by:ysimon
  • 5
  • 4
  • 3
  • +1
14 Comments
 
LVL 13

Expert Comment

by:Epsylon
ID: 6235825
Do you properly check the return value of getFirstChild? It could return nil.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6235832
And aren't you mixing up GetNextSibling with GetNextChild?

What are you trying to do with these function anyway?
0
 

Author Comment

by:ysimon
ID: 6235940
I checked the return value, not nil, even error happend.
I used both functions in a loop in order to find the final Node.

Tree:
00-0F
 00
 01
 02
 ..
 0F
01-1F
 10
 11
 12
 ..

My program:

function TMainForm.GetCodeNode(B: Byte): TTreeNode;
var I: Integer;
    Node: TTreeNode;
begin
     Node:=TreeView1.TopItem;
     for I:=1 to B div 16 do
     begin
       Node:=Node.getNextSibling;
     end;
     Node:=Node.getFirstChild;
     for I:=1 to (B mod 16) do
     begin
       Node:=Node.getNextSibling;
     end;
     Result:=Node.getFirstChild;
end;

GetCodeNode($12) it should return 10-1F -> 12 Node

Please look if there is hidden bug in that routine.

Thanks

ysimon
 
0
ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
LVL 13

Expert Comment

by:Epsylon
ID: 6236064
I think the last line of TMainForm.GetCodeNode should be:

    Result:=Node;
0
 

Author Comment

by:ysimon
ID: 6236278
Yes, your right. But it works when TreeView is never clicked.

Thanks

ysimon
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6236355
What exactly goes wrong then? Here it always works.

This is what I did:

function TMainForm.GetCodeNode(B: Byte): TTreeNode;
var I: Integer;
   Node: TTreeNode;
begin
    Node:=TreeView1.TopItem;
    for I:=1 to B div 16 do
    begin
      Node:=Node.getNextSibling;
    end;
    Node:=Node.getFirstChild;
    for I:=1 to (B mod 16) do
    begin
      Node:=Node.getNextSibling;
    end;
    Result:=Node;
end;

procedure TMainForm.Button1Click(Sender: TObject);
begin
  TreeView1.HideSelection := false;
  TreeView1.Selected := GetCodeNode($12);
end;


No matter what I do, it always goes to the '12' node under '10-1F' when I click Button1.
0
 
LVL 3

Accepted Solution

by:
alzv earned 100 total points
ID: 6237390
One note. TopItem propertu returns node which is CURRENTLY shown topmost in the treeview. It will be changed if you scroll treeview. If you want to use first node, use TreeView.Items[0]. So, try to replace first string of your procedure
Node:=TreeView1.TopItem;

to

Node := TreeView1.Items[0];

Best regards,
Alexey Zverev.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6237417
Or Treeview1.GetFirstNode
0
 
LVL 3

Expert Comment

by:alzv
ID: 6240561
Hello, ysimon.

Did you solve your problem? And in this case who is the winner?

Best regards,
Alexey Zverev.
0
 

Author Comment

by:ysimon
ID: 6241511
Yes I have solved my problem. Thank you alzv.
I changed Node:=TreeView1.TopItem;
to
Node := TreeView1.Items[0];
it works fine, no error message.

Thank you alzv.

ysimon

0
 
LVL 3

Expert Comment

by:alzv
ID: 6242137
And who wins the points?

Best regards,
Alexey Zverev.
0
 

Author Comment

by:ysimon
ID: 6242981
I think alzv should win 100 points.
The key in my problem is that I must change
Node:=TreeView1.TopItem;
to
Node := TreeView1.Items[0];

Thanks again.

ysimon
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6872387
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101 or Netminder will return to finalize these if still open in seven days.  Please post closing recommendations before that time.

Question(s) below appears to have been abandoned. Your options are:
 
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you. You must tell the participants why you wish to do this, and allow for Expert response.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question. Again, please comment to advise the other participants why you wish to do this.

For special handling needs, please post a zero point question in the link below and include the question QID/link(s) that it regards.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click the Help Desk link on the left for Member Guidelines, Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Please click you Member Profile to view your question history and keep them all current with updates as the collaboration effort continues, to track all your open and locked questions at this site.  If you are an EE Pro user, use the Power Search option to find them.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.11866558.html
http://www.experts-exchange.com/questions/Q.20107980.html
http://www.experts-exchange.com/questions/Q.20112507.html
http://www.experts-exchange.com/questions/Q.20121203.html
http://www.experts-exchange.com/questions/Q.20122370.html
http://www.experts-exchange.com/questions/Q.20128022.html
http://www.experts-exchange.com/questions/Q.20128024.html
http://www.experts-exchange.com/questions/Q.20143035.html
http://www.experts-exchange.com/questions/Q.20145949.html
http://www.experts-exchange.com/questions/Q.20164917.html
http://www.experts-exchange.com/questions/Q.20164983.html
http://www.experts-exchange.com/questions/Q.20171798.html
http://www.experts-exchange.com/questions/Q.20179154.html
http://www.experts-exchange.com/questions/Q.20192667.html
http://www.experts-exchange.com/questions/Q.20192583.html
http://www.experts-exchange.com/questions/Q.20200806.html
http://www.experts-exchange.com/questions/Q.20201786.html
http://www.experts-exchange.com/questions/Q.20201947.html
http://www.experts-exchange.com/questions/Q.20246959.html
http://www.experts-exchange.com/questions/Q.20252474.html
http://www.experts-exchange.com/questions/Q.20259886.html
http://www.experts-exchange.com/questions/Q.20270462.html
http://www.experts-exchange.com/questions/Q.20273241.html


To view your locked questions, please click the following link(s) and evaluate the proposed answer.
http://www.experts-exchange.com/questions/Q.20265181.html
http://www.experts-exchange.com/questions/Q.20277546.html

PLEASE DO NOT AWARD THE POINTS TO ME.  
 
------------>  EXPERTS:  Please leave any comments regarding your closing recommendations if this item remains inactive another seven (7) days.  Also, if you are interested in the cleanup effort, please click this link http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643
 
Thank you everyone.
 
Moondancer
Moderator @ Experts Exchange

P.S.  For any year 2000 questions, special attention is needed to ensure the first correct response is awarded, since they are not in the comment date order, but rather in Member ID order.
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 7079706
Zero response from anyone, finalized.
Moondancer - EE Moderator
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

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…
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 quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

832 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