I wish to use the Data (pointer) property of the TTreeNode by putting a TGUID into it. Anybody got an idea how to achieve this?
Here's a part of the code, might help you guys understand what I'm trying to do.
if Assigned(trNode) then
begin
trNode := tvMain.Items.Add(trNode, dmMain.qryTreeView.FieldByName('SomeColumn').Text);
gID := StringToGUID(dmMain.qryTreeView.FieldByName('ID').Text);
trNode.Data := //how do I do this?
The best way to handle this is to derive a new class from TTreeNode
and give it a TGUID
data member, then use the TTreeView.OnCreateNodeClass
event to let the TreeView create instances of your class. This way, the RTL automatically manages the memory for your guid values for you (and lets you customize the nodes any other way you wish). To access the guids, all you have to do is type-cast the TTreeNode
pointers when needed. For example:
type
TMyTreeNode = class(TTreeNode)
public
Guid: TGuid;
end;
procedure TMyForm.tvMainCreateNodeClass(Sender: TCustomTreeView; var NodeClass: TTreeNodeClass);
begin
NodeClass := TMyTreeNode;
end;
trNode := tvMain.Items.Add(...);
TMyTreeNode(trNode).Guid := StringToGUID(...);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With