Recent

Author Topic: can't add new treenode  (Read 620 times)

sydenis

  • Jr. Member
  • **
  • Posts: 55
can't add new treenode
« on: December 05, 2025, 10:56:36 am »
I have a code that removes child nodes from a selected TTreeNode and adds there a new child nodes

Code: Pascal  [Select][+][-]
  1. Node.DeleteChildren;
  2. Node.TreeNodes.AddChild(Node, 'Child 1');
  3. Node.TreeNodes.AddChild(Node, 'Child 2');

As a result, the old nodes disappear, but no new ones appear. Why?

jamie

  • Hero Member
  • *****
  • Posts: 7493
Re: can't add new treenode
« Reply #1 on: December 05, 2025, 11:06:00 am »
What OS ?
The only true wisdom is knowing you know nothing

sydenis

  • Jr. Member
  • **
  • Posts: 55
Re: can't add new treenode
« Reply #2 on: December 05, 2025, 11:09:05 am »
win10 + lazarus 4.4

jamie

  • Hero Member
  • *****
  • Posts: 7493
Re: can't add new treenode
« Reply #3 on: December 05, 2025, 11:39:05 am »
Try removing treenodes in the mix.

Node.addchild(..........)
The only true wisdom is knowing you know nothing

sydenis

  • Jr. Member
  • **
  • Posts: 55
Re: can't add new treenode
« Reply #4 on: December 05, 2025, 11:47:30 am »
Node.addchild(..........)
there is no such method in lazarus)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12021
  • Debugger - SynEdit - and more
    • wiki
Re: can't add new treenode
« Reply #5 on: December 05, 2025, 11:51:55 am »
Code: Pascal  [Select][+][-]
  1. procedure TTreeNode.DeleteChildren;
  2. begin
  3.   if Owner<>nil then Owner.ClearCache;
  4.   Collapse(true);
  5.   HasChildren := False;
  6. end;
  7.  

Have you tried to expand the nodes?

sydenis

  • Jr. Member
  • **
  • Posts: 55
Re: can't add new treenode
« Reply #6 on: December 05, 2025, 12:05:56 pm »
Yes. The node has an icon to expand, but nothing happens when clicked. If I remove the line
Code: Pascal  [Select][+][-]
  1. Node.DeleteChildren;
from the code then nodes are added normally

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12021
  • Debugger - SynEdit - and more
    • wiki
Re: can't add new treenode
« Reply #7 on: December 05, 2025, 12:29:25 pm »
Then maybe you also need to set
  HasChildren := true;

If so (not tested): Strange, maybe a bug, don't know what is/was indented.

jamie

  • Hero Member
  • *****
  • Posts: 7493
Re: can't add new treenode
« Reply #8 on: December 05, 2025, 01:36:37 pm »
I just ran a test on the trunk because that is what's next to me atm and I can't varify your findings, it all works as it should.

I am wondering if maybe you have implemented some of the events and maybe have interfered with the operation of the OnAdditon for example and related items, like OnDelete etc.

I can upload the app I used to test.

Jamie
The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 7493
Re: can't add new treenode
« Reply #9 on: December 05, 2025, 01:42:04 pm »
Test app
The only true wisdom is knowing you know nothing

sydenis

  • Jr. Member
  • **
  • Posts: 55
Re: can't add new treenode
« Reply #10 on: December 05, 2025, 03:07:36 pm »
I am wondering if maybe you have implemented some of the events and maybe have interfered with the operation of the OnAdditon for example and related items, like OnDelete etc.

Yes. I override the expand method in the descendant of TreeView
and added the deletion of old children there so that the latest information is displayed when reopening.
There seems to be a problem here

jamie

  • Hero Member
  • *****
  • Posts: 7493
Re: can't add new treenode
« Reply #11 on: December 05, 2025, 03:31:58 pm »
I don't why you would to an override but maybe you didn't property call the inherited code?

Jamie
The only true wisdom is knowing you know nothing

sydenis

  • Jr. Member
  • **
  • Posts: 55
Re: can't add new treenode
« Reply #12 on: December 05, 2025, 03:39:28 pm »
I moved Node.DeleteChildren to the Collapse method of descendant. Everything is fine now

 

TinyPortal © 2005-2018