[Solved] Processing of selections in FileListBox content in order of selection? lazarus / 31-LCL ---------------------------------------------------------------------- loaded · 2022-01-29 06:34 Hi All, I have a code that gets selected files in FileListBox. But if I want to get them in the order of selection, things get complicated. As an alternaive ; I thought about moving the rows up and down, but that didn't seem very practical to me. Is there a ready solution for this on the FileListBox side? Or should I create my own solution? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  i:integer;  p1:UTF8String;begin  for i:=0 to FileListBox1.Items.Count-1 do  begin    if FileListBox1.Selected[i] then    begin       p1:= '"'+FileListBox1.Directory+'\'+FileListBox1.Items[i]+'" ';       // Todo    end;  end;end; I would be glad if you share your thoughts on the subject. Respects. ---------------------------------------------------------------------- Thaddy · 2022-01-29 07:06 On select, add the selection to a queue and do not process yet. Then process the items in the queue. A queue is FIFO. There are several good (de)queues available in the standard fpc distribution. E.g. fgl, generics.collections,  contnrs. You can also use a Tstrings descendant as a queue. I am not aware that a listbox (any) has such functionality, although re-ordering is possible. I always would go for a queue, it is easy and exactly what you asked. ---------------------------------------------------------------------- loaded · 2022-01-29 07:12 Thank you so much for the reply Thaddy Yes, as you said, I can do this if the selection process is made one by one, but if multiple selections are made with the "shift" key from time to time, the circuits light up.  Or I should have a coffee now, maybe I can do it later. ---------------------------------------------------------------------- ccrause · 2022-01-29 07:23 Quote from: loaded on January 29, 2022, 08:12:38 amThank you so much for the reply Thaddy Yes, as you said, I can do this if the selection process is made one by one, but if multiple selections are made with the "shift" key from time to time, the circuits light up.  Or I should have a coffee now, maybe I can do it later. While you wait for the coffee to kick in - if you want to really mimick the user actions, expand Thaddy's suggestion by tracking selection changes via OnSelectionChange event. If this event doesn't give you the required resolution, then hook all possible user actions (OnKeyDown/Up, OnMouseDown/Up etc.) and track the selection process that way (although this will require quite a bit of extra work). ---------------------------------------------------------------------- loaded · 2022-01-29 07:33 Thank you so much for the reply ccrause Yes, you are right, I drank my coffee and Lazarus I'm driving at full speed on the streets  of FileListBox behind the wheel of ---------------------------------------------------------------------- engkin · 2022-01-29 08:09 From user perspective, the order would not be clear. Find a better alternative like using two ListBoxes. ---------------------------------------------------------------------- loaded · 2022-01-29 08:43 Thank you so much for the reply king I specifically needed this feature for pdf merging with Ghostscript because pdfs need to be merged in the order they are selected. Finally, a cup of coffee + 2 cups of linden + some inspiration and the result I want; Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FileListBox1SelectionChange(Sender: TObject; User: boolean);var  i,im:integer;  fsname:UTF8String;  mc:Boolean;begin  for im:=Memo_File_Selects.lines.count downto 0  do  begin    mc:=true;    for i:=0 to FileListBox1.Items.Count-1 do    begin      fsname:= '"'+FileListBox1.Directory+'\'+FileListBox1.Items[i]+'"';      if (FileListBox1.Selected[i]) and (fsname=Memo_File_Selects.Lines.Strings[im]) then      begin      mc:=false;      end;    end;    if mc then Memo_File_Selects.Lines.Delete(im);  end;   for i:=0 to FileListBox1.Items.Count-1 do  begin    if FileListBox1.Selected[i] then    begin       fsname:= '"'+FileListBox1.Directory+'\'+FileListBox1.Items[i]+'"';       mc:=false;         for im:=0 to Memo_File_Selects.lines.count do       begin             if (fsname=Memo_File_Selects.Lines.Strings[im]) then             begin             mc:=true;             end;         end;         if not mc then  Memo_File_Selects.lines.Add(fsname);    end;  end;end; With the power of tea I wrote a program on the subject and published it on my site, I also prepared a video and added it to youtube. https://www.youtube.com/watch?v=_lNgJ1HuYHk ---------------------------------------------------------------------- engkin · 2022-01-29 19:48 Well done! It reminds me of PDFTools. ---------------------------------------------------------------------- loaded · 2022-01-30 05:26 Quote from: engkin on January 29, 2022, 08:48:06 pmWell done! It reminds me of PDFTools. Master engkin , I'm glad you like it. Whatever I did, I did it thanks to the masters in this forum. Thank you always be present.