Reported by Hans Voogt; checked by Reinier Sterkenburg
According to the help file (TControl.Parent):
Changing the parent of a control moves the control onscreen so that it is
displayed within the parent.
If you happen to do this with a TTreeView of which you have set the Property
HasChildren of 1 or more nodes, the value of this property will be lost.
Source code example:
Form with 2 panels, on Panel1 a TTreeview with Align = alClient.
Upon running, Treeview1 will display the root node and his 10 children, all
with a '+'. Should be so because HasChildren is set to true.
Change the parent by clicking Button1 and the + signs of the children will
disappear.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
TreeView1: TTreeView;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
var
i: Integer;
Root: TTreeNode;
begin
Root := TreeView1.Items.Add(nil, 'Root'); // Add root node
for i := 0 to 9 do
with TreeView1.Items.AddChild(Root, IntToStr(i)) do // Add 10 children
HasChildren := True; // Make '+' appear
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
TreeView1.Parent := Panel2; // Switch Parents
end;
end.
Cause :
Upon looking at the source code (comctrls) of TTreeNode I found that in
TTreenode.ReadData & TTreeNode.WriteData HasChildren is not read/written.
Comparing the code with TTreeNode.Assign shows that 2 more properties are
not read/written by the reader/writer: Cut and DropTarget (Focus also
doesn't get read/written but I can see the logic in that). |