Recent

Author Topic: Change in TreeView (treeview.inc)  (Read 601 times)

jcmontherock

  • Jr. Member
  • **
  • Posts: 80
Change in TreeView (treeview.inc)
« on: November 27, 2021, 12:06:11 pm »
Hello,
I suggest a little change in the function FindNodeWithText:
Change:
Code: Pascal  [Select][+][-]
  1. function TTreeNodes.FindNodeWithText(const NodeText: string): TTreeNode;
  2. begin
  3.   Result := GetFirstNode;
  4.   while Assigned(Result) and (Result.Text <> NodeText) do
  5.     Result := Result.GetNext;
  6. end;
  7.  

To:
Code: Pascal  [Select][+][-]
  1. function TTreeNodes.FindNodeWithText(StrtIndex: Integer = 0; const NodeText: string): TTreeNode;
  2. begin
  3.   Result := TreeView1.Items[StrtIndex];
  4.   while Assigned(Result) and (Result.Text <> NodeText) do
  5.     Result := Result.GetNext;
  6. end;
  7.  

If you have 2 (or more) nodes with the same text with a different parent node, you cannot find the next one.

wp

  • Hero Member
  • *****
  • Posts: 9021
Re: Change in TreeView (treeview.inc)
« Reply #1 on: November 27, 2021, 12:49:45 pm »
Please post this in the bugtracker and mark it as feature request. The optional parameter must be at the end, though.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 7517
  • Debugger - SynEdit - and more
    • wiki
Re: Change in TreeView (treeview.inc)
« Reply #2 on: November 27, 2021, 01:12:08 pm »
Also, since it returns a TTreeNode, maybe it should take a TTreeNode as optional arg?

Code: Pascal  [Select][+][-]
  1. function TTreeNodes.FindNodeWithText(const NodeText: string; ContinueAfterNode: TTreeNode = nil): TTreeNode;

Just an idea.

Alextp

  • Hero Member
  • *****
  • Posts: 1479
    • UVviewsoft
Re: Change in TreeView (treeview.inc)
« Reply #3 on: November 27, 2021, 01:37:52 pm »
Martin, +1.

jcmontherock

  • Jr. Member
  • **
  • Posts: 80
Re: Change in TreeView (treeview.inc)
« Reply #4 on: November 27, 2021, 03:45:45 pm »
Fine, it's more better...

 

TinyPortal © 2005-2018