Recent

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

jcmontherock

  • Full Member
  • ***
  • Posts: 234
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.
Windows 11 UTF8-64 - Lazarus 3.2-64 - FPC 3.2.2

wp

  • Hero Member
  • *****
  • Posts: 11855
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.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9792
  • 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: 2386
    • UVviewsoft
Re: Change in TreeView (treeview.inc)
« Reply #3 on: November 27, 2021, 01:37:52 pm »
Martin, +1.

jcmontherock

  • Full Member
  • ***
  • Posts: 234
Re: Change in TreeView (treeview.inc)
« Reply #4 on: November 27, 2021, 03:45:45 pm »
Fine, it's more better...
Windows 11 UTF8-64 - Lazarus 3.2-64 - FPC 3.2.2

 

TinyPortal © 2005-2018