• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 513
  • Last Modified:

TreeView in Delphi 5

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
ysimon
Asked:
ysimon
  • 5
  • 4
  • 3
  • +1
1 Solution
 
EpsylonCommented:
Do you properly check the return value of getFirstChild? It could return nil.
0
 
EpsylonCommented:
And aren't you mixing up GetNextSibling with GetNextChild?

What are you trying to do with these function anyway?
0
 
ysimonAuthor Commented:
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
EpsylonCommented:
I think the last line of TMainForm.GetCodeNode should be:

    Result:=Node;
0
 
ysimonAuthor Commented:
Yes, your right. But it works when TreeView is never clicked.

Thanks

ysimon
0
 
EpsylonCommented:
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
 
alzvCommented:
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
 
EpsylonCommented:
Or Treeview1.GetFirstNode
0
 
alzvCommented:
Hello, ysimon.

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

Best regards,
Alexey Zverev.
0
 
ysimonAuthor Commented:
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
 
alzvCommented:
And who wins the points?

Best regards,
Alexey Zverev.
0
 
ysimonAuthor Commented:
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
 
MoondancerCommented:
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
 
MoondancerCommented:
Zero response from anyone, finalized.
Moondancer - EE Moderator
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now