Docking problem

I created a simple form (TForm) that includes just a TTreeView-Control. I fill this TTreeView within the Form with the following method:

procedure TChildSystemView.UpdateTree;
  node: TTreeNode;
  childNode: TTreeNode;
  i: Integer;
  node := SystemTree.Items.Add(nil, FLeagueSystem.SystemName);
  node.ImageIndex := 0;
  node.SelectedIndex := 0;
  if FLeagueSystem.NumberOfLeagues > 0 then
            for i := 1 to FLeagueSystem.NumberOfLeagues do begin
          childNode := SystemTree.Items.AddChild(node, FLeagueSystem.Leagues[i - 1].LeagueName);
      childNode.ImageIndex := 1;
      childNode.SelectedIndex := 1;

This works fine. But this window is a dockable window within a parent Form and it is docked by default when I start the program. This works fine too. The problem is that when I undock the window and I re-dock it to the parent, all data within the tree is lost. What can I do?
Who is Participating?
LischkeConnect With a Mentor Commented:
No reaction, then LOCK.
just a lame attempt: did you try calling update function from forms repaint event handler?
klusiAuthor Commented:
no, but this seems useless because I saw in the debugger that after the re-dock the tree's items-property was set to nil ! So it was empty and an update should give nothing.
Oh this looks as would the tree window be recreated which usually kills the content (although the VCL contains code to save the nodes to restore them later). Unfortunately, the Windows treeview is such a badly made thing you will get very often problems if you want to do something more than the absolute basics. I recommend that you save the tree content to a memory stream just before you change its dock state and restore it after that.

Another point, look at my home page and download TreeNT, which is a free tree implementation which tries to get around many of the problems (though not always successfully).

Ciao, Mike
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.