Delphi - virtual row tree slow GetText method with a large number of nodes

I am not very experienced with the TVirtualStringTree component yet, so maybe I forgot something trivial.

My application collects information about a file into a record (file_name, path, size) and displays the data in a virtual row tree.

Now that there are many nodes (200K +), I am experiencing a strong slowdown, the whole tree is basically lagging. I know that the amount of memory is quite large only with the recording data, but I found that the lag is caused by the OnGetText method for VST. It doesn’t matter if this method reads the actual data or sets CellText to a static line (for example, CellText: = 'Test';), the slowdown is significant. If I exit OnGetText without installing CellText, it works great - even with an integer of 1,000,000 nodes in my tree. Also, if I destroy Tree (FullCollapse) by hiding this method, 90% of my nodes, OnGetText behaves normally, or at least is much better.

As far as I understand, OnGetText is called only for really visible screen nodes, so I don’t understand why this is such a problem with a large number of nodes in the tree.

Does anyone have any clues for me to point me in the direction?

EDIT:

Delphi Version: D2010 VST Version: 4.8.6

My code in its simplest test form basically looks like this:

var
  SkipGetText : boolean;

procedure TXForm.VSTGetText(Sender: TBaseVirtualTree;
  Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType; var CellText: string);
begin
  if SkipGetText then exit;
  CellText := 'TEST';
  // actual code commented out to reduce complications
end;

If I installed CellText, it lags; if I exit, it is not. Oddly enough, further scrolling down worsens.

Here is what is assigned as NodeData:

type
  PVSData = ^Fi;
  Fi = Packed Record
    Name, Dir, Ext: String;
    Size: Int64;
  end;

procedure TXForm.AddFile( const RootFolder:string; const SR: TSearchRec );
var
  FileInfo: PVSData;
  FileSize: Int64;
  Node: PVirtualNode;
begin
  Node          := VST.AddChild(nil);
  INC(AllFiles);
  FileInfo      := VST.GetNodeData(Node);
  FileInfo^.Name := SR.Name;
  FileInfo^.Dir  := RootFolder;

  Int64Rec(FileSize).Hi := SR.FindData.nFileSizeHigh;
  Int64Rec(FileSize).Lo := SR.FindData.nFileSizeLow;
  FileInfo^.Size         := FileSize;
end;

procedure TXForm.VSTPaintText(Sender: TBaseVirtualTree;
const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType);
begin
  if SkipPaintText then exit;

  case ListView.GetNodeLevel(Node) of
    0: TargetCanvas.Font.Color := Color1;
    else TargetCanvas.Font.Color := Color2;
  end;
end;

procedure TXForm.VSTBeforeCellPaint(Sender: TBaseVirtualTree;
  TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
  CellPaintMode: TVTCellPaintMode; CellRect: TRect; var ContentRect: TRect);
begin
  case ListView.GetNodeLevel(Node) of
    0: TargetCanvas.Font.Color := Color1;
    else TargetCanvas.Font.Color := Color2;
  end;
end;

I noticed that expanding / collapsing and re-expanding somehow seems to improve the situation, but it's outside of me to understand why this can really affect.

+3
source share
4 answers

. , . node node. , , , node, . .

+1

- , .

+3

, Delphi . , D2009, TVirtualTreeView WideString, , - --, AnsiString , . D2009 TVirtualTreeView WideString UnicodeString.

+1

, , VST , . , - , , , node?

+1

Source: https://habr.com/ru/post/1756998/


All Articles