3
votes

I would like to implement a search procedure to a VirtualStringTree and I would like to do it by comparing the search text with the text from node and not from the pointer (eg. Data^.Column0) because this is not always as String.

Please help me with a suggestion to get back the text from node as it is.

For a better understanding see bellow code (I adjust an example from Lazarus)

type
  PTreeData = ^TTreeData;
  TTreeData = record
    Column0: TDate; //Date
    Column1: Integer; //Integer
    Column2: String;
  end;

procedure TForm1.VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
 Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
var
  Data: PTreeData;
begin
  Data := VST.GetNodeData(Node);
  case Column of
    0: CellText := DateToStr(Data^.Column0); //2015-05-11 or 11-05-2015
    1: CellText := IntToStr(Data^.Column1) + ' days'; //22 days
    2: CellText := Data^.Column2;
  end;
end;
1
How are you planning to get data for nodes if you have them linked through the node data pointer ? If you are asking how to write a generic solution, then your question (most probably) narrows to how to search for simple types by text, and throw away the virtual tree and pointer stuff. The rest what would remain is I'm having a collection of records (internally in virtual tree through the node pointers), in which I want to search any simple type field by text.TLama
If there is no way then I will add to the record Column0AsText which will be the Data^.Column0AsText:= DateToStr(Data^.Column0) and I will implement the search through the strings.REALSOFO
I can't make sense of this. You already have code to return a textual representation of each column.David Heffernan

1 Answers

3
votes

If you want to get a virtual tree view cell text, then you can use the Text property. That will internally trigger the OnGetText event and you'll be able to obtain the text just like you are returning it to display in the tree:

var
  S: string;
  Node: PVirtualNode;
  Column: TColumnIndex;
begin
  ...
  S := VirtualStringTree.Text[Node, Column];
end;