Board index » delphi » A CREATED TTreeNode not owned by TTreeNodes

A CREATED TTreeNode not owned by TTreeNodes

Hello,

   Is it possible to create a TTrenode not owned by a TTreeNodes?
For example this simple code (the shortest I can think of) will
raise an EAccessViolation exception when the Free method is called.
So, no problem for the creation, but what to do for the disposal?

procedure TForm1.FormCreate(Sender: TObject);
var
  TreeNode : TTreeNode;
begin
  TreeNode := TTreeNode.Create(nil);
  TreeNode.Free;
end;

Thanks,

Jacques

 

Re:A CREATED TTreeNode not owned by TTreeNodes


Quote
Jacques Melancon wrote in message <3640FC5C.18711...@mail.polymtl.ca>...

>   Is it possible to create a TTrenode not owned by a TTreeNodes?
>For example this simple code (the shortest I can think of) will
>raise an EAccessViolation exception when the Free method is called.
>So, no problem for the creation, but what to do for the disposal?

A TTreenode can only *logically* exist within a treeview and wasn't intended
to be created outside of the methods of a TTreeview control. The reason is
that a TTreenode doesn't actually store the data - it is simply an OOP
wrapper around the API that manages items in the Windows TTreeview. So for
example, you'll also get an access violation if you try to assign a string
to the TTreenode's Text property because that causes the component to send a
Windows message using the owner's Handle property. The destroy method also
tries to access owner properties.

Therefore, there is no way to make any use of an orphaned TTreeview. And
there is no way to "transfer" a TTreenode object from 1 TTreeview to
another, you would need to create one and copy the data, then delete the
other.

--
Wayne Niddery - WinWright Consulting
Delphi, C++Builder, JBuilder, InterDev --
http://home.ican.net/~wniddery/RADBooks.html
...remove chaff when replying...
"You know you've landed gear-up when it takes full power to taxi"

Other Threads