Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I need to use a class instead of record for VirtualStringTree node.
Should I declare it standard (but in this case - tricky) way like that:
PNode = ^TNode;
TNode = record
obj: TMyObject;
fNd: PNode;
begin
fNd:= vstTree.getNodeData(vstTree.AddChild(nil));
fNd.obj:= TMyObject.Create;
or should I use directly TMyObject
? If so - how?!
How about assigning (constructing) the object and freeing it?
Thanks in advance
vstTree.NodeDataSize := SizeOf(TMyObject);
Get the datasize holder and bind to your object
vstTree.getNodeData(passed in interested node)^ := your object
vstTree.getNodeData(vstTree.AddChild(nil))^ := TMyObject.Create;
use vstTree.InsertNode method
To free the binding object hookup the OnFreeNode event
vstTree.OnFreeNode := FreeNodeMethod;
procedure TFoo.FreeNodeMethod(Sender: TBaseVirtualTree; Node: PVirtualNode);
P: ^TMyObject;
begin
P := Sender.getNodeData(Node);
if P <> nil then
begin
P^.Free;
P^ := nil; //for your safety or you can omit this line
you could create the object instance after receiving the node data, as in :
fNd:= vstTree.getNodeData(vstTree.AddChild(nil));
fnd.obj := TMbyObject.Create;
or you could try and assign it directly
Pointer(Obj) := vstTree.getNodeData(...);
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.