JAM-Software / Virtual-TreeView

Virtual Treeview is a Delphi treeview control
http://www.jam-software.de/virtual-treeview/
640 stars 248 forks source link

GetNodeData returns invalid data when (Node = Pointer(Self)) #1265

Open chuacw opened 2 weeks ago

chuacw commented 2 weeks ago

When Node is Pointer(Self) in GetNodeData, it should return nil, instead of returning @Node.Data, ie... the code for GetNodeData should be updated to:

function TBaseVirtualTree.GetNodeData(Node: PVirtualNode): Pointer;
// Returns the address of the user defined data area in the node.
begin
  Assert((FNodeDataSize > 0) or not Assigned(Node), 'NodeDataSize not initialized.');
  if (FNodeDataSize <= 0) or (Node = nil) or (Node = FRoot) or (Node = Pointer(Self)) then
    Result := nil
  else
  begin
    Result := @Node.Data;
    Include(Node.States, vsOnFreeNodeCallRequired); // We now need to call OnFreeNode, see bug #323
  end;
end;
joachimmarder commented 1 week ago

it should return nil, instead of returning @Node.Data

@chuacw : Can you please explain why you think that?

Self (the object pointer to a virtual tree instance) is not a valid input for GetNodeData() and the pointer type of the parameter does not match. So why should we care?