I'm sure I'm doing something horribly wrong as my child node has two icons drawn ontop of each other...
I have set the initial root node and set it's data to point to my singleton. I use an interface to define a node on the tree. The following is in the code that adds the root node:
vstProjectExplorer.AddChild(nil, Pointer(IProjectTreeNode(FProject)))
Then I implement reset and init node events like so:
procedure TfrmMain.vstProjectExplorerInitNode(Sender: TBaseVirtualTree;
ParentNode, Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates);
var
ptNode: IProjectTreeNode;
n : PVirtualNode;
i : Integer;
begin
ptNode := IProjectTreeNode(Sender.GetNodeData(Node)^);
Sender.DeleteChildren(Node, False);
for i := 0 to ptNode.GetNodeChildrenCount - 1 do
begin
Sender.AddChild(Node, Pointer(ptNode.GetNodeChild(i)));
end;
end;
procedure TfrmMain.vstProjectExplorerResetNode(Sender: TBaseVirtualTree;
Node: PVirtualNode);
var
ptNode: IProjectTreeNode;
begin
ptNode := IProjectTreeNode(Sender.GetNodeData(Node)^);
Sender.ChildCount[Node] := ptNode.GetNodeChildrenCount;
end;
And to update the tree when a project is loaded I do this:
vstProjectExplorer.BeginUpdate;
vstProjectExplorer.ReinitNode(vstProjectExplorer.RootNode, True);
vstProjectExplorer.EndUpdate;
vstProjectExplorer.Refresh;
And finally, here is the interface itself:
const
IID_PROJECTTREENODE : TGuid = '{0AC71B6A-E552-4CA6-ADE4-F89304821180}';
type
IProjectTreeNode = interface
[IID_PROJECTTREENODE]
function GetNodeTitle: String;
function GetNodeImageIndex: Integer;
function GetNodeChildrenCount: Integer;
function GetNodeChild(Index: Integer): IProjectTreeNode;
function GetNodeAutoExpand: Boolean;
end;
Getting the image index and text are done pretty much the same (I just cut the code out of the events and put tem next to each other here):
CellText := IProjectTreeNode(Sender.GetNodeData(Node)^).GetNodeTitle;
ImageIndex := IProjectTreeNode(Sender.GetNodeData(Node)^).GetNodeImageIndex;
It ~seems~ to work, but it shows the two images ontop of each other as noted in the attached image. Am I doing it all wrong, or is it something simple/obvious.