【问题标题】:TVirtualStringTree: How to get edited text?TVirtualStringTree:如何获取已编辑的文本?
【发布时间】:2014-11-03 14:45:53
【问题描述】:

我正在编辑 TVirtualStringTree 中显示节点的第二列。但是在编辑完成后,我无法使用 Sender.GetNodeData(Node) 检索文本 - 它不包含任何文本。

如何获取 OnEdited 事件中的文本?还有其他方法可以获取编辑后的文本吗?我已经阅读了 Virtual Treeview CHM 帮助文档的前几个常见问题页面,还参考了答案in this SO question,但找不到答案。

这里是当前代码:

  TTherapData = record
    TherapID: Integer;
    TherapName: String[120];
    TherapInstr: String[120];
    Selected: Byte;
  end;

  PTherapData = ^TTherapData;

procedure TfmPatient_Conslt.vstRxList_AsgEdited(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex);
var
  TherapData: PTherapData;
begin
  TherapData := Sender.GetNodeData(Node);
  if Assigned(TherapData) then
  begin
    TherapData^.TherapInstr := vstRxList_Asg.Text[Node, 1];
    showmessage(TherapData^.TherapInstr);
  end;

  FTherapDataListAsg_Iter := 0;
  vstRxList_Asg.NodeDataSize := SizeOf(TTherapData);
  vstRxList_Asg.RootNodeCount := 0;
  vstRxList_Asg.RootNodeCount := TherapDataList_CountSelectedItems;

end;

【问题讨论】:

    标签: delphi virtualtreeview tvirtualstringtree


    【解决方案1】:

    感谢TLama的提示,答案是处理OnNewText事件:

    procedure TfmPatient_Conslt.vstRxList_AsgNewText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex;
      NewText: string);
    var
      TherapData: PTherapData;
    begin
    
      if (Column = 1) then
      begin
        TherapData := Sender.GetNodeData(Node);
        if Assigned(TherapData) then
          TherapData^.TherapInstr := NewText;
      end;
    
    end;
    

    【讨论】:

    • @RobKennedy:要么答案有问题,要么我的代码有问题,因为它没有按预期工作。 GetNodeData 返回的指针指向与树中存储的地址不同的地址。我通过检查变量的地址(在 Debug->Evaluate/Modify 中)知道这一点。我该如何解决?如果需要更多信息,我准备发布完整的代码,但它是一个很长的单元。
    • @RobKennedy:我注意到了这个问题,因为我的数据库“保存”例程没有“看到”对数据所做的更新(在编辑树中的单元格之后)。
    • 很抱歉听到这个消息。听起来你需要修改你的答案。接受它显然为时过早。另一方面,我不确定您在这里报告的内容是否真的是您的答案有问题,或者只是其他一些不相关的问题。进行一些调试以缩小范围。 As I explained before, GetNodeData doesn't necessarily return the actual address of Node.Data,所以不要指望它。
    猜你喜欢
    • 2015-04-22
    • 1970-01-01
    • 1970-01-01
    • 2017-09-18
    • 1970-01-01
    • 2022-12-04
    • 2015-06-14
    • 2013-10-25
    • 1970-01-01
    相关资源
    最近更新 更多