TBaseVirtualTree.OnIncrementalSearch Event

Virtual Tree View

Miscellaneous event.

Pascal
property OnIncrementalSearch: TVTIncrementalSearchEvent;
Description

This event is integral part of the incremental search functionality (see also Keyboard, hotkeys and incremental search). It is triggered during search for a node which matches the given string. Similar to other compare routines return a value < 0 if the node's caption is considered as being before the given text, = 0 if it is the same and > 0 if it is considered being after the given text. 

 

procedure TfrmProperties.VST3IncrementalSearch(Sender: TBaseVirtualTree; Node: PVirtualNode; const Text: WideString;
  var Result: Integer);

var
  S, PropText: string;


begin
  // Note: This code requires a proper Unicode/WideString comparison routine which I did not want to link here for
  // size and clarity reasons. For now strings are (implicitly) converted to ANSI to make the comparison work.
  // Search is not case sensitive.
  S := Text;
  if Node.Parent = Sender.RootNode then
  begin
    // root nodes
    if Node.Index = 0 then
      PropText := 'Description'
    else
      PropText := 'Origin';
  end
  else
  begin
    PropText := PropertyTexts[Node.Parent.Index, Node.Index, ptkText];
  end;

  // By using StrLIComp we can specify a maximum length to compare. This allows us to find also nodes
  // which match only partially.
  Result := StrLIComp(PChar(S), PChar(PropText), Min(Length(S), Length(PropText)))
end;
Notes

Usually incremental search allows to match also partially. Hence it is recommended to do comparison only up to the length 

of the shorter string.

Class
Links
What do you think about this topic? Send feedback!