Recent

Author Topic: Help VirtualStringTree search/filter nodes  (Read 7928 times)

todhuk

  • New Member
  • *
  • Posts: 15
Help VirtualStringTree search/filter nodes
« on: October 20, 2017, 05:05:47 pm »
I want to search for text in TVirtualStringTree.

However, I get a line error:
Error: Wrong number of parameters specified for call to "SearchText"

This is the code:

Code: Pascal  [Select][+][-]
  1. procedure TMainForm.SearchText(Sender: TBaseVirtualTree; Node: PVirtualNode; Data: Pointer; var Abort: Boolean);
  2. var
  3.   NodeData: PData;
  4.   sText: String;
  5.   bVisible: Boolean;
  6. begin
  7.   NodeData := Sender.GetNodeData(Node);
  8.   Abort := False;
  9.   bVisible := True;
  10.   sText := String(data);
  11.   if Length(sText) > 0 then
  12.   begin
  13.     if Pos(sText, NodeData^.BName) <> 1 then
  14.     begin
  15.       bVisible := False;
  16.     end;
  17.   end;
  18.   Sender.IsVisible[Node] := bVisible;
  19. end;
  20.  
  21. procedure TMainForm.btnSearch1Click(Sender: TObject);
  22. var
  23.   foundNode  : PVirtualNode;
  24. begin
  25.   VST1.BeginUpdate;
  26.   try
  27.    foundNode :=VST1.IterateSubtree(nil, SearchText, PChar(findEdit.Text));
  28.   finally
  29.     VST1.EndUpdate;
  30.   end;
  31. end;
  32.  

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Help VirtualStringTree search/filter nodes
« Reply #1 on: October 20, 2017, 05:17:02 pm »
Code: Pascal  [Select][+][-]
  1.  foundNode :=VST1.IterateSubtree(nil, @SearchText, PChar(findEdit.Text));//Pay attention to the symbol @.
  2.  
This should solve it, if not post again I'll take a closer look.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

WooBean

  • Full Member
  • ***
  • Posts: 230
Re: Help VirtualStringTree search/filter nodes
« Reply #2 on: October 20, 2017, 05:23:56 pm »
Hi, todhuk!

First, try to read what you are going to post.
Explain what is "VST1" (variable or property type). I think that you will find the answer by yourself.
« Last Edit: October 20, 2017, 05:33:59 pm by WooBean »
Platforms: Win7/64, Linux Mint Ulyssa/64

Thaddy

  • Hero Member
  • *****
  • Posts: 14364
  • Sensorship about opinions does not belong here.
Re: Help VirtualStringTree search/filter nodes
« Reply #3 on: October 20, 2017, 05:34:36 pm »
SearchText needs a var parameter...... Which needs to be declared AND initialized beforehand.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

todhuk

  • New Member
  • *
  • Posts: 15
Re: Help VirtualStringTree search/filter nodes
« Reply #4 on: October 20, 2017, 05:35:15 pm »
Okay taazz
But why in the example "Advanced"(see unit VisibilityDemo) of the VirtualTreeView package, everything works without "@"?

Thaddy

  • Hero Member
  • *****
  • Posts: 14364
  • Sensorship about opinions does not belong here.
Re: Help VirtualStringTree search/filter nodes
« Reply #5 on: October 20, 2017, 05:36:13 pm »
Mode delphi? First count your parameters...
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

todhuk

  • New Member
  • *
  • Posts: 15
Re: Help VirtualStringTree search/filter nodes
« Reply #6 on: October 20, 2017, 06:00:48 pm »
well, thank you!  :)

majid.ebru

  • Hero Member
  • *****
  • Posts: 502
Re: Help VirtualStringTree search/filter nodes
« Reply #7 on: March 10, 2018, 06:06:12 am »
Hi

Code: Pascal  [Select][+][-]
  1. procedure SearchText
  2. (Sender:TBaseVirtualTree;Node:PVirtualNode;Data:Pointer;var Abort:Boolean);
  3. var
  4.   NodeData: PMyNode;
  5.   sText: String;
  6.   bVisible: Boolean;
  7. begin
  8.   NodeData := Sender.GetNodeData(Node);
  9.   Abort := False;
  10.   bVisible := True;
  11.   sText := String(data);
  12.   if Length(sText) > 0 then
  13.   begin
  14.     if Pos(sText, NodeData^.Col1) <> 1 then
  15.     begin
  16.       bVisible := False;
  17.     end;
  18.   end;
  19.   Sender.IsVisible[Node] := bVisible;
  20. end;
  21. //-----------------
  22.  
  23.  
  24. procedure TFormMain.B_T3_1_5Click(Sender: TObject);
  25. var
  26.   foundNode  : PVirtualNode;
  27. begin
  28.   VST.BeginUpdate;
  29.   try
  30.    foundNode :=VST.IterateSubtree(nil, @SearchText, PChar(E_T3_1_5.Text));
  31.   finally
  32.     VST.EndUpdate;
  33.   end;
  34. end;
  35.  


i use these codes but i have error:
Code: Pascal  [Select][+][-]
  1. foundNode :=VST.IterateSubtree(nil, @SearchText, PChar(E_T3_1_5.Text));


unit_Main.pas(4434,51) Error: Incompatible type for arg no. 2: Got "<address of procedure(TBaseVirtualTree;PVirtualNode;Pointer;var Boolean);Register>", expected "<procedure variable type of procedure(TBaseVirtualTree;PVirtualNode;Pointer;var Boolean) of object;Register>"

balazsszekely

  • Guest
Re: Help VirtualStringTree search/filter nodes
« Reply #8 on: March 10, 2018, 08:15:49 am »
Add SearchMain to TFormMain's private section:
procedure TFormMain.SearchText (...

majid.ebru

  • Hero Member
  • *****
  • Posts: 502
Re: Help VirtualStringTree search/filter nodes
« Reply #9 on: March 10, 2018, 04:55:24 pm »
@GetMem thank you

it worked but it doesn't work true?!?

i search "B4000"

this item is visible ( visible is true)

but all parent of this item(B4000) is invisible(visible is false) and i can't see B4000?

how can i show all parent of item?
(how can i set visible ture all of parent?)

balazsszekely

  • Guest
Re: Help VirtualStringTree search/filter nodes
« Reply #10 on: March 10, 2018, 05:58:31 pm »
@maid.ebru
I have no idea what are you trying to achieve. Why B4000 parents are not visible? Anyway let's say you find B4000 and you wish to set all it's parents visibility to true, you can try something like this:
Code: Pascal  [Select][+][-]
  1. //  Node is B4000 here  
  2.   Node := Node^.Parent; //<--B4000 parent
  3.   while Node <> nil do
  4.   begin
  5.     VST.IsVisible[Node] := True;
  6.     Node := Node^.Parent; //<--B4000 grand parent and so one
  7.   end;

 

TinyPortal © 2005-2018