How does the TVirtualTreeview editor work?

Viewed 755

I am exploring Virtual Treeview in Delphi and ran a sample program where the editor is invoked by pressing F2 beginning the editing process uses the built-in editor in Virtualtreeview (No attached editing component). The text changed, but immediately changed back to the original when I clicked on a different node.

This led me to explore the source code in VirtualTrees.pas to study how the editing process works. Everything appears to boil down to the TBaseVirtualTree.doedit. I have examined each step but am uncertain what exactly operates the editing box positioned in the column.

procedure TBaseVirtualTree.DoEdit;

begin
  Application.CancelHint;
  StopTimer(ScrollTimer);
  StopTimer(EditTimer);
  DoStateChange([], [tsEditPending]);
  if Assigned(FFocusedNode) and not (vsDisabled in FFocusedNode.States) and
    not (toReadOnly in FOptions.FMiscOptions) and (FEditLink = nil) then
  begin
    FEditLink := DoCreateEditor(FFocusedNode, FEditColumn);
    if Assigned(FEditLink) then
    begin
      DoStateChange([tsEditing], [tsDrawSelecting, tsDrawSelPending, tsToggleFocusedSelection, tsOLEDragPending,
        tsOLEDragging, tsClearPending, tsDrawSelPending, tsScrollPending, tsScrolling, tsMouseCheckPending]);
      ScrollIntoView(FFocusedNode, toCenterScrollIntoView in FOptions.SelectionOptions,
        not (toDisableAutoscrollOnEdit in FOptions.AutoOptions));
      if FEditLink.PrepareEdit(Self, FFocusedNode, FEditColumn) then
      begin
        UpdateEditBounds;
        // Node needs repaint because the selection rectangle and static text must disappear.
        InvalidateNode(FFocusedNode);
        if not FEditLink.BeginEdit then
          DoStateChange([], [tsEditing]);
      end
      else
        DoStateChange([], [tsEditing]);
      if not (tsEditing in FStates) then
        FEditLink := nil;
    end;
  end;
end;

So my question is how is the actual keyboard input being placed in the node.text by VirtualTree and how is the result of the edit placed into the data record?

1 Answers
Related