Recent

Author Topic: [SOLVED] VST button Prev and Next  (Read 321 times)

Pe3s

  • Full Member
  • ***
  • Posts: 242
[SOLVED] VST button Prev and Next
« on: August 18, 2022, 09:14:14 pm »
Hello, I wrote the code that selects VST elements after pressing the button, unfortunately it does not work if we have multiselect option turned on in VST how can I improve the code?

Code: Pascal  [Select][+][-]
  1. procedure TForm1.SpeedButton3Click(Sender: TObject);
  2. var
  3.   Node: PVirtualNode;
  4.   Data: PData;
  5. begin
  6.   Node := VST.GetFirstSelected;
  7.   if Node = nil then
  8.     Node := VST.GetFirst()
  9.   else
  10.     Node := VST.GetNext(Node);
  11.  
  12.     VST.Selected[Node] := True;
  13.     VST.SetFocus;
  14.  
  15.     Data := VST.GetNodeData(VST.GetFirstSelected);
  16.     Image1.Picture.LoadFromFile(Data^.PATH + Data^.FImage);
  17. end;
« Last Edit: August 19, 2022, 07:49:12 pm by Pe3s »

dje

  • Full Member
  • ***
  • Posts: 107
Re: VST button Prev and Next
« Reply #1 on: August 19, 2022, 06:50:25 pm »
I guess you would like the selection cleared?
Code: Pascal  [Select][+][-]
  1.   Node := VST.GetFirstSelected;
  2.   if Node = nil then Node := VST.GetFirst
  3.   else
  4.     Node := VST.GetNext(Node);
  5.   if Assigned(Node) then begin // <- Check for nil here. ie: GetNext from last node returns nil.
  6.     VST.ClearSelection; // <- Clear selection here
  7.     VST.Selected[Node] := True;
  8.     VST.SetFocus;
  9.     Data := VST.GetNodeData(VST.GetFirstSelected);
  10.     Image1.Picture.LoadFromFile(Data^.PATH + Data^.FImage);
  11.   end;  

Note: Personally, I'd make it cycle when reaching the end of nodes.
« Last Edit: August 19, 2022, 06:52:46 pm by derek.john.evans »

Pe3s

  • Full Member
  • ***
  • Posts: 242
Re: VST button Prev and Next
« Reply #2 on: August 19, 2022, 07:48:56 pm »
@derek.john.evan Thank you :)

 

TinyPortal © 2005-2018