Board index » cppbuilder » TREEVIEW Searching TEXT!

TREEVIEW Searching TEXT!


2006-01-20 03:55:45 AM
cppbuilder78
Hi All
Good New Year for all os us.
I trying to search a text in a TreeView but i dont know how to navigate
trought the nodes.
Thanks
Edward
 
 

Re:TREEVIEW Searching TEXT!

OK i found the anwser more fast.
BUT NOW I NEED TO SELECT THE ITEM ON TREEVIEW
Edward
TTreeNode *pItem = new TTreeNode(NULL);
pItem=TreeViewRA->Items->GetFirstNode();
while(pItem!=NULL)
{
if(pItem->Text.AnsiPos(EditRA->Text.UpperCase()) !=0 )
{
ShowMessage(pItem->Text);
}
pItem=pItem->GetNext();
}
delete pItem;
"Edward" < XXXX@XXXXX.COM >wrote in message
Quote
Hi All

Good New Year for all os us.

I trying to search a text in a TreeView but i dont know how to navigate
trought the nodes.

Thanks

Edward

 

Re:TREEVIEW Searching TEXT!

"Edward" < XXXX@XXXXX.COM >wrote in message
Quote
OK i found the anwser more fast.
The answer you have is not entirely correct. See futher below.
Quote
BUT NOW I NEED TO SELECT THE ITEM ON TREEVIEW
Please do not shout.
TTreeNode has Selected and Focused properties for what you ask.
Quote
TTreeNode *pItem = new TTreeNode(NULL);
That is a memory leak. You are never freeing that TTreeNode instance
because ...
Quote
pItem=TreeViewRA->Items->GetFirstNode();
... you are overriding the pointer immediately afterwards, thus you lose the
memory address of the TTreeNode that you created and thus can never free it
property.
Quote
delete pItem;
That statement has no meaning in the code you showed. The only way to reach
that line is when the loop exits, which does not happen until pItem is NULL,
so you are always freeing a NULL pointer, which does nothing.
In any case, you are not supposed to be creating new TTreeNode instances to
begin with just to navigate the existing nodes. Get rid of the 'new' and
'delete' statements altogether, ie:
TTreeNode *pItem = TreeViewRA->Items->GetFirstNode();
while( pItem )
{
if( pItem->Text.AnsiPos(EditRA->Text.UpperCase()) !=0 )
{
pItem->MakeVisible();
pItem->Selected = true;
pItem->Focused = true;
break;
}
pItem = pItem->GetNext();
}
Gambit
 

{smallsort}

Re:TREEVIEW Searching TEXT!

THANKS GAMBIT
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Edward" < XXXX@XXXXX.COM >wrote in message
news:43cff5ef$ XXXX@XXXXX.COM ...

>OK i found the anwser more fast.

The answer you have is not entirely correct. See futher below.

>BUT NOW I NEED TO SELECT THE ITEM ON TREEVIEW

Please do not shout.

TTreeNode has Selected and Focused properties for what you ask.

>TTreeNode *pItem = new TTreeNode(NULL);

That is a memory leak. You are never freeing that TTreeNode instance
because ...

>pItem=TreeViewRA->Items->GetFirstNode();

... you are overriding the pointer immediately afterwards, thus you lose
the
memory address of the TTreeNode that you created and thus can never free
it
property.

>delete pItem;

That statement has no meaning in the code you showed. The only way to
reach
that line is when the loop exits, which does not happen until pItem is
NULL,
so you are always freeing a NULL pointer, which does nothing.

In any case, you are not supposed to be creating new TTreeNode instances
to
begin with just to navigate the existing nodes. Get rid of the 'new' and
'delete' statements altogether, ie:

TTreeNode *pItem = TreeViewRA->Items->GetFirstNode();
while( pItem )
{
if( pItem->Text.AnsiPos(EditRA->Text.UpperCase()) !=0 )
{
pItem->MakeVisible();
pItem->Selected = true;
pItem->Focused = true;
break;
}

pItem = pItem->GetNext();
}


Gambit


 

Re:TREEVIEW Searching TEXT!

Edward wrote:
Quote
THANKS GAMBIT
Please do not shout again. <g>
And please trim your quotes.
Hans.
 

Re:TREEVIEW Searching TEXT!

At 23:45:51, 19.01.2006, Edward wrote:
Quote
THANKS GAMBIT
Edward, you quoted*) 53 lines, and only added the text above. Please note
that this is a violation of the guidelines in
support.borland.com/entry.jspa rule #1.
*)Quoting is copying (automatically or manually) text from the previous
message into your own. Quoted lines are usually marked by one or more>
at the beginning of the line. Please don't quote entire messages, but
only just enough to give the reader a reference. More on proper quoting
can be found here:
blogs.teamb.com/rudyvelthuis/articles/7509.aspx
www.uwasa.fi/~ts/http/quote.html
alt-usage-english.org/posting_quotes.html
Thanks for your future compliance with Borland's guidelines.
--
Rudy Velthuis [TeamB] rvelthuis.de/
"The graveyards are full of indispensable men."
- Charles de Gaulle (1890-1970)
 

Re:TREEVIEW Searching TEXT!

ok