1

I'm editing the 2nd column of a displayed node in the TVirtualStringTree. However after the edit is complete it I'm unable to retrieve the text using Sender.GetNodeData(Node) - it contains no text.

How can I get the text in the OnEdited event? Is there some other way to get the edited text? I've read the first few FAQ pages of the Virtual Treeview CHM help documentation and also refered to the answer in this SO question but could not find the answer.

Here is the present code:

  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;
Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
Steve F
  • 1,527
  • 1
  • 29
  • 55

1 Answers1

1

Thanks to hint from TLama, the answer is to handle the OnNewText event:

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;
Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467
Steve F
  • 1,527
  • 1
  • 29
  • 55
  • @RobKennedy: Either there is a problem with the answer or something wrong with my code because its not working as expected. The pointer returned by GetNodeData points to a different address than that from the one stored in the tree. I know this by examining the addresses (in Debug->Evaluate/Modify) of the variables. How can I fix it? If more info is needed I'm ready to post the complete code, but its a very long unit. – Steve F Nov 06 '14 at 14:41
  • @RobKennedy: I noticed the problem because my database 'save' routine is not 'seeing' the updates made to the data (after editing the cell in the tree). – Steve F Nov 06 '14 at 14:47
  • Sorry to hear that. Sounds like you need to rework your answer. Accepting it was apparently premature. On the other hand, I'm not sure whether what you're reporting here is really a problem with your answer, or just some other unrelated problem. Do some debugging to narrow it down. [As I explained before, `GetNodeData` doesn't necessarily return the actual address of `Node.Data`](http://stackoverflow.com/a/26636017/33732), so don't count on that. – Rob Kennedy Nov 06 '14 at 15:06