Firemonkey TTreeView – Storing object references in TTreeViewItems, TValue


Was trying the same way as for the good old VCL TTreeNode. Ok, there is no TTreeNode and there is no method to add treenodes to the tree, instead i have to manually create TTreeViewItem instances and set it’s parent property to a TTreeView instance. Now, TTreeViewItem has a data property but it’s type is TValue.

How to handle this type?

I tried the following:

TMaster = class(TDevice)


mstitem := TTreeViewItem.create(self);
mstitem.parent := TreeView1; := TMaster.Create(i, ‘master’+ inttostr(i));

procedure TForm1.TreeView1Click(Sender: TObject);
obj: TObject;
selectednode := TTreeView1.Selected;
obj := TDevice(selectednode.Data.AsObject); //Invalid typecast
if obj is TDevice then
showmessage( TDevice(obj).DevName );

Comments are closed.