Forum > LCL
[SOLVED] Add folder to VST
Pe3s:
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 [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Button1Click(Sender: TObject);var list: TStringList; S: String;begin ListBox1.Clear; list := FindAllFiles(ExtractFileDir(Application.ExeName) + '\images', '*.jpg', True); for S in list do ListBox1.Items.Add(ExtractFileNameOnly(S)); list.Free;end;
code VST
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Button1Click(Sender: TObject);var SL: TStringList; Node: PVirtualNode; Data: PData;begin SL:= TStringList.Create; try SL:= FindAllFiles(ExtractFileDir(Application.ExeName) + '\Images', '*.jpg', True); Node:= VST.GetFirst; while Assigned(Node) dobegin VST.NodeDataSize := SizeOf(TData); Node := VST.AddChild(nil); Data := VST.GetNodeData(Node); Data^.Kategoria := ExtractFileNameOnly(SL) Data:= VST.GetNodeData(Node); Node:= VST.GetNext(Node); end; finally Sl.Free; end;end;
jamie:
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[?]);
KodeZwerg:
Small demo attached. Hope it helps you to figure out how it works / how it can work.
Pe3s:
Thank you :)
KodeZwerg:
--- Quote from: Pe3s on December 03, 2022, 09:59:58 am ---Thank you :)
--- End quote ---
You are welcome, for more Examples you can watch it on Github. :D
Navigation
[0] Message Index
[#] Next page