How do I get a second descendant of TTreeViewItem to show on the TreeView

  

Using Delphi 10.3 and Fmx, how do I get the second descendant of TTreeviewItem to show its text ? The first descendant works fine. The second one (T3) always shows blank. In this sample the “Parent” and “Text” are assigned correctly to the Item. But in my project the parent will not get assigned, but the text will.

unit Unit1;

interface

uses
System.SysUtils, System.Types, System.UITypes, System.Classes,
System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics,
FMX.Dialogs, FMX.Layouts, FMX.TreeView;

type
TForm1 = class(TForm)
vue: TTreeView;
procedure FormCreate(Sender: TObject);
private
public
end;

var
Form1: TForm1;

type
T1 = class (TTreeViewItem)
constructor Create (AOwner : TTreeViewItem); reintroduce; virtual;
end;

T2 = class (TTreeViewItem)
constructor Create (AOwner : TTreeViewItem); reintroduce; virtual;
end;

T3 = class (T1)
constructor Create (AOwner : TTreeViewItem); override;
end;

implementation

{$R *.fmx}

{ T1 }

constructor T1.Create(AOwner: TTreeViewItem);
begin
inherited Create (AOwner);
Parent := AOwner;
Text := ‘T1’;
end;

{ T2 }

constructor T2.Create(AOwner: TTreeViewItem);
begin
inherited Create (Aowner);
Parent := AOwner;
Text := ‘T2’;
end;

{ T3 }

constructor T3.Create(AOwner: TTreeViewItem);
begin
inherited;
// Parent := AOwner;
Text := ‘T3’;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
R,
I1, I2 : TTreeViewItem;
T1a : T1;
T2a : T2;
T3a : T3;
begin
R := TTreeViewItem.Create (vue);
R.Parent := vue; R.Text := ‘Root’;
{ Doesnt Work }
I1 := TTreeViewItem.Create (R);
I1.Parent := R; I1.Text := ‘First’;
{ Works }
I2 := TTreeViewItem.Create (R);
I2.Parent := R; I2.Text := ‘Second’;

{ This works }
T1a := T1.Create (I1);
{ This works }
T2a := T2.Create (I1);
{ This doesnt work }
T3a := T3.Create (I1);
end;

end.

Here’s the dfm

object Form1: TForm1
Left = 0
Top = 0
Caption = ‘Form1’
ClientHeight = 480
ClientWidth = 640
FormFactor.Width = 320
FormFactor.Height = 480
FormFactor.Devices = [Desktop]
OnCreate = FormCreate
DesignerMasterStyle = 0
object vue: TTreeView
Align = Left
Size.Width = 217.000000000000000000
Size.Height = 480.000000000000000000
Size.PlatformDefault = False
TabOrder = 0
Viewport.Width = 213.000000000000000000
Viewport.Height = 476.000000000000000000
end
end

Comments are closed.