Recent

Author Topic: [SOLVED] Add folder to VST  (Read 812 times)

Pe3s

  • Hero Member
  • *****
  • Posts: 533
[SOLVED] Add folder to VST
« on: December 02, 2022, 09:33:10 pm »
Hello, I wrote a code that loads images into a Listbox, I wanted to write a code that loads images into a VirtualStringTree, but I messed something up. How to fix VST code to work?
Code Listbox
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   list: TStringList;
  4.   S: String;
  5. begin
  6.   ListBox1.Clear;
  7.   list := FindAllFiles(ExtractFileDir(Application.ExeName) + '\images', '*.jpg', True);
  8.   for S in list do ListBox1.Items.Add(ExtractFileNameOnly(S));
  9.   list.Free;
  10. end;
  11.  

code VST
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   SL: TStringList;
  4.   Node: PVirtualNode;
  5.   Data: PData;
  6. begin
  7.   SL:= TStringList.Create;
  8.   try
  9.     SL:= FindAllFiles(ExtractFileDir(Application.ExeName) + '\Images', '*.jpg', True);
  10.     Node:= VST.GetFirst;
  11.     while Assigned(Node) do
  12. begin
  13.   VST.NodeDataSize := SizeOf(TData);
  14.   Node := VST.AddChild(nil);
  15.   Data := VST.GetNodeData(Node);
  16.   Data^.Kategoria := ExtractFileNameOnly(SL)
  17.   Data:= VST.GetNodeData(Node);
  18.   Node:= VST.GetNext(Node);
  19.   end;
  20.   finally
  21.     Sl.Free;
  22.   end;
  23. end;
  24.  
« Last Edit: December 03, 2022, 10:00:23 am by Pe3s »

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Add folder to VST
« Reply #1 on: December 02, 2022, 11:56:28 pm »
ExtractFileNameOnly(...) accepts a STRING only, not a Stringlist.

You need to index it to get the entry you want.

 so it looks like you are in a loop and you need a counter as you add nodes. That counter is also used to index the stringList ..

 ExtractFileNameOnly(SL[?]);
The only true wisdom is knowing you know nothing

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2007
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Add folder to VST
« Reply #2 on: December 03, 2022, 12:34:17 am »
Small demo attached. Hope it helps you to figure out how it works / how it can work.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

Pe3s

  • Hero Member
  • *****
  • Posts: 533
Re: Add folder to VST
« Reply #3 on: December 03, 2022, 09:59:58 am »
Thank you  :)

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2007
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Add folder to VST
« Reply #4 on: December 03, 2022, 06:52:21 pm »
Thank you  :)
You are welcome, for more Examples you can watch it on Github:D
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

Pe3s

  • Hero Member
  • *****
  • Posts: 533
Re: [SOLVED] Add folder to VST
« Reply #5 on: December 11, 2022, 01:05:12 pm »
 :)

 

TinyPortal © 2005-2018