Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/VCL/Win 32 Controls/TTreeView    [ Add a report in this area ]  
Report #:  107228   Status: Reported
References to TTreeNodes change when TTreview's container's Parent is changed
Project:  Delphi Build #:  11.0.2902.10471
Version:    11.2 Submitted By:   Pedro Rodriguez Cervera
Report Type:  Issue Date Reported:  7/19/2012 4:31:14 AM
Severity:    Extreme corner case Last Updated: 7/26/2012 5:50:23 PM
Platform:    All versions Internal Tracking #:  
Resolution: None (Resolution Comments) Resolved in Build: : None
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: None
Description
References to TTreeNodes change when TTreview's container's Parent is changed.

When user clicks button1 it shows the problem.
The first ShowMessage shows '1?-2?-3?' but the second ShowMessage shows '3?-2?-1?'(variables dont reference the same nodes)

VCL Forms Application Project with two forms:
Form1 is the Main Form.
----------------
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls, ExtCtrls, Unit2;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
    aux: TForm2;
    N1, N2, N3: TTreeNode;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  aux:= TForm2.Create(nil);
  N1:= aux.TreeView1.Items.Add(nil, '1?');
  N2:= aux.TreeView1.Items.Add(nil, '2?');
  N3:= aux.TreeView1.Items.Add(nil, '3?');
  ShowMessage(N1.Text+'-'+N2.Text+'-'+N3.Text);
  aux.Parent:= Panel1;
  aux.Show;
  ShowMessage(N1.Text+'-'+N2.Text+'-'+N3.Text);
end;

end.
----------------

----------------
unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, StdCtrls;

type
  TForm2 = class(TForm)
    TreeView1: TTreeView;
  private
    { Private declarations }
  public
    { Public declarations }
  end;
implementation
{$R *.dfm}

end.
----------------
Steps to Reproduce:
1. Create a VCL Application Forms Project with the source (In Full Description)
2. Run Application
3. Click Button1

When user clicks button1 it shows the problem.
The first ShowMessage shows '1?-2?-3?' but the second ShowMessage shows '3?-2?-1?'(variables dont reference the same nodes)
Workarounds
None
Attachment
Project1.zip
Comments

Tomohiro Takahashi at 7/19/2012 6:10:24 PM -
> 1. Create a VCL Application Forms Project with the source (In Full Description)
Could you please attach entire sample project(as a .zip) to this report by using Windows Native QC Client?
The standalone client comes with Delphi.

Pedro Rodriguez Cervera at 7/20/2012 3:35:36 AM -
How I Can attach a zip? The Attachment zone is disabled.

Tomohiro Takahashi at 7/21/2012 6:10:38 AM -
Please use Windows Native QC Client to attach a .zip file to your existing report.
The standalone client comes with Delphi.
Thanks.

Pedro Rodriguez Cervera at 7/25/2012 1:27:31 AM -
I did it!

Tomohiro Takahashi at 7/25/2012 6:55:24 PM -
>   aux.Parent:= Panel1;
Does your issue occur only when merging child form into main form's panel?

and, I think that when changing Parent proeprty, entire child form has been re-created internally(e.g., Window Handle etc...), so we should not shrare TTreeNode references.
Please try to add 3 lines as below.
----------
procedure TForm1.Button1Click(Sender: TObject);
begin
  aux:= TForm2.Create(nil);
  N1:= aux.TreeView1.Items.Add(nil, '1?');
  N2:= aux.TreeView1.Items.Add(nil, '2?');
  N3:= aux.TreeView1.Items.Add(nil, '3?');
  ShowMessage(N1.Text+'-'+N2.Text+'-'+N3.Text);
  aux.Parent:= Panel1;
  aux.Show;
  N1 := aux.TreeView1.Items[0]; // Added
  N2 := aux.TreeView1.Items[1]; // Added
  N3 := aux.TreeView1.Items[2]; // Added
  ShowMessage(N1.Text+'-'+N2.Text+'-'+N3.Text);
end;
----------

Pedro Rodriguez Cervera at 7/26/2012 12:23:59 AM -
Project1 is a simple example. In then real project, child form doesn't public its TTreeview, It only publics TTreeNode references. Main form cannot re-assign TTreeView references, but...I think It's possible to do it in Child form, in its DoShow. Thanks!

Server Response from: ETNACODE01