Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to ensure that every node in a TTreeView is unique (2) Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
31-Oct-02
Category
VCL-General
Language
Delphi 2.x
Views
71
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

I have a 3 level TTreeview. The nodes in levels 2 and 3 must have unique captions 
(text). Items will be added in a loop so I can't check the "Selected" text against 
the data to be entered. However, I will know which node where data entry will 
begin. If adding child nodes to a node on level 2 for example, I assume I need to 
loop through the children of the particular parent node of the node on level 2 and 
check the text property? Does this make sense?

Answer:

Yes. Use the edited nodes Parent.GetfirstChild to get a reference to the first 
child node of that parent. Then use that nodes GetNextSibling to find the next node 
on that level to examine, and so on. Untested:

1   function IsDuplicateNode(aNode: TTreenode): Boolean;
2   var
3     walker: TTreenode;
4   begin
5     Assert(Assigned(aNode), 'Need a node to examine!');
6     if Assigned(aNode.Parent) then
7       walker := aNode.Parent.GetFirstChild
8     else
9       walker := TTreeview(aNode.Treeview).Items[0];
10    Result := False;
11    while Assigned(walker) do
12    begin
13      if (walker <> aNode) and AnsiSametext(walker.Text, aNode.Text) then
14      begin
15        Result := true;
16        Break;
17      end;
18      walker := walker.GetNextSibling;
19    end;
20  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC