I have a Virtual Treeview with multiline nodes. However when the text in the nodes gets bigger the scrolling of the tree gets intolerably slow. A quick look into a simple "one node with large text" application with sampling profiler shows that most of the time is spent in gdi32.dll.

I have a Virtual Treeview with multiline nodes. However when the text in the nodes gets bigger the scrolling of the tree gets intolerably slow. A quick look into a simple "one node with large text" application with sampling profiler shows that most of the time is spent in gdi32.dll.

So I guess somehow the painting code has an issue with the large text. Anyone know a solution?

Here is the code required to reproduce the problem:

procedure TForm1.FormCreate(Sender: TObject);
begin
  VirtualStringTree1.TreeOptions.MiscOptions :=
    VirtualStringTree1.TreeOptions.MiscOptions + [toVariableNodeHeight];
  VirtualStringTree1.RootNodeCount := 1;
end;

procedure TForm1.VirtualStringTree1GetText(Sender: TBaseVirtualTree;
  Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType;
  var CellText: string);
begin
  CellText := s; // >20000 characters and the problem becomes visible
end;

procedure TForm1.VirtualStringTree1InitNode(Sender: TBaseVirtualTree;
  ParentNode, Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates);
begin
  Sender.MultiLine[Node] := True;
end;

procedure TForm1.VirtualStringTree1MeasureItem(Sender: TBaseVirtualTree;
  TargetCanvas: TCanvas; Node: PVirtualNode; var NodeHeight: Integer);
begin
  NodeHeight := 1500;
end;

Comments

  1. Any way to control buffering?  Is it bitmap shuffling or text measurements that causes the slowdown?

    ReplyDelete
  2. Cesar Romero Not available on the VTV (at least it wasn't in the OI) and on the form it did not change anything.

    ReplyDelete
  3. avoid scrolling, use tooltip instead with limited size, clip any extra text.

    ReplyDelete
  4. Heinz Toskano Seriously, I am not talking about megabytes of text but about text that might be dozens or a couple hundred lines long that I want to watch in the tree.

    ReplyDelete
  5. Stefan Glienke I understand, but you are trying to use a tool for a purpose it wasn't designed. Labels in a treeview are just that labels. For longer texts, drop a tooltip or a memo (worst case imho).

    ReplyDelete
  6. To whoever deleted my comment:

    I don't mind that (I realise the intent). However deleting the comment makes me no longer receive updates on the post, which I do mind.

    Thus I'd prefer if you simply edited the comment, for example replacing it with "mod: comment removed to improve S/N ratio".

    ReplyDelete
  7. OP/Mods can't edit comments - they can only remove them or flag them. I guess it was OP that removed it?

    ReplyDelete
  8. Lars Fosdal Well that sucks. I only noticed my comment was removed because I was browsing the community and saw this post had comments I hadn't been notified of.

    ReplyDelete
  9. I just run into same problem.
    Stefan Glienke did you find any solution for VTV?

    ReplyDelete
  10. No, I cut the text at some point and provide the ability to copy the entire text with Ctrl+C

    ReplyDelete

Post a Comment