Recent

Author Topic: SelectDirectory dialog, how does Multi-select work?  (Read 4706 times)

KarenT

  • Full Member
  • ***
  • Posts: 120
SelectDirectory dialog, how does Multi-select work?
« on: November 15, 2018, 05:05:24 pm »
I'd like to select multiple Folders so I have the "AllowMultiSelect" checked but it still only returns the last Folder selected in, of all things, "Filename."

I can't find a StringList or delimited-String that might have all the selected Folders.

How do I get all the selected Folders/Directories?

Thank you.

ASerge

  • Hero Member
  • *****
  • Posts: 2223
Re: SelectDirectory dialog, how does Multi-select work?
« Reply #1 on: November 15, 2018, 05:22:52 pm »
I'd like to select multiple Folders so I have the "AllowMultiSelect" checked but it still only returns the last Folder selected in, of all things, "Filename."
TOpenDialog.Files or TSelectDirectoryDialog.Files

wp

  • Hero Member
  • *****
  • Posts: 11857
Re: SelectDirectory dialog, how does Multi-select work?
« Reply #2 on: November 15, 2018, 05:26:09 pm »
This works (don't forget to set the Option ofAllowMultiSelect):

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   if SelectDirectoryDialog1.Execute then
  4.     Listbox1.Items.Assign(SelectDirectoryDialog1.Files);
  5. end;  

KarenT

  • Full Member
  • ***
  • Posts: 120
Re: SelectDirectory dialog, how does Multi-select work?
« Reply #3 on: November 15, 2018, 08:13:43 pm »
Thanks to you both. Sorry for asking seemingly obvious questions but I could not find that with online searches.

I had tried "Items" but no luck there.

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: SelectDirectory dialog, how does Multi-select work?
« Reply #4 on: November 15, 2018, 08:39:53 pm »
Have you solved it? If haven't, you can try my code:

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Dialogs, StdCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     SelectDirectoryDialog1: TSelectDirectoryDialog;
  17.     procedure Button1Click(Sender: TObject);
  18.   end;
  19.  
  20. var
  21.   Form1: TForm1;
  22.  
  23. implementation
  24.  
  25. {$R *.lfm}
  26.  
  27. { TForm1 }
  28.  
  29. procedure TForm1.Button1Click(Sender: TObject);
  30. var
  31.   OpenOptions : TOpenOptions;
  32.   AllDirs     : string;
  33.   S           : string;
  34. begin
  35.   OpenOptions := SelectDirectoryDialog1.Options;
  36.   Include(OpenOptions, ofAllowMultiSelect);
  37.   SelectDirectoryDialog1.Options := OpenOptions;
  38.   if not(SelectDirectoryDialog1.Execute) then Exit;
  39.  
  40.   AllDirs := '';
  41.   for S in SelectDirectoryDialog1.Files do
  42.     AllDirs :=  AllDirs + S + LineEnding;
  43.   ShowMessage(AllDirs + 'Total: '+ SelectDirectoryDialog1.Files.Count.ToString);
  44. end;
  45.  
  46. end.

KarenT

  • Full Member
  • ***
  • Posts: 120
Re: SelectDirectory dialog, how does Multi-select work?
« Reply #5 on: November 15, 2018, 11:54:00 pm »
Thanks, that helped. I have it working just fine now.

wp

  • Hero Member
  • *****
  • Posts: 11857
Re: SelectDirectory dialog, how does Multi-select work?
« Reply #6 on: November 15, 2018, 11:55:21 pm »
Sorry for asking seemingly obvious questions but I could not find that with online searches.
It was not obvious at all...

Maybe you want to know how I found it out? I dropped a TSelectDirectoryDialog on the form, then CTRL-clicked on the class name in the form declaration. This opens the unit Dialogs in which TSelectDirectoryDialog is implemented. Maybe you have to press SHIFT+CTRL+ArrowUp to get to the interface part of the unit. I scanned the public and published properties - there are none. Then I looked at the inheritance of the component: it inherits from TOpenDialog. Again CTRL-click on TOpenDialog to jump to the code of TOpenDialog. Now the same story again: Look at the public and published properties - nothing related. Repeat with the ancestor of TOpenDialog, TFileDialog. - Here we are: among the public declarations there is a property Files of type TStrings. Since we only moved within the inheritance tree of TSelectDirectoryDialog the property Files must be available for this class, too.

Knowing this way of navigation through the source code gives you access to the most up-to-date documentation: the source code itself.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: SelectDirectory dialog, how does Multi-select work?
« Reply #7 on: November 16, 2018, 12:32:30 am »
It was not obvious at all...

Maybe you want to know how I found it out? I dropped a TSelectDirectoryDialog on the form, then CTRL-clicked on the class name [...]

Or one could, maybe, open the LCL help, search for TSelectDirectoryDialog and click on "Properties" 8)

ETA: The help files are not always the best reference--that's the source itself--but it should be the first consulted. RTFM and all that :)
« Last Edit: November 16, 2018, 12:37:50 am by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

KarenT

  • Full Member
  • ***
  • Posts: 120
Re: SelectDirectory dialog, how does Multi-select work?
« Reply #8 on: November 16, 2018, 04:27:46 pm »
RTFM and all that :)

Kinda rude and uncalled for.

My second sentence in the OP was intended to indicate that I had done just that. I dd not see "Files" as I was looking for Folders or a delimited string for Folder name. It is odd enough that FPC deem to regard the return String for a specifically stated as a Directory(Folder) search, as a FIlename.

I do not come here and ask until I feel I have exhausted all of the search terns I can think of.

wp

  • Hero Member
  • *****
  • Posts: 11857
Re: SelectDirectory dialog, how does Multi-select work?
« Reply #9 on: November 16, 2018, 04:56:51 pm »
I think lucamar did not address the "RTFM" to you, I understand his message as a response to my own post describing the source code navigation. He certainly is right, but knowing the poor quality of the help files I almost never look into the help files and almost always search information in the way I described. And knowing how to navigate inside complex source code is a key requirement when you want to understand the LCL or IDE internally.

I do agree that a property named "Files" is misleading for a component which searches for folders. Maybe the inherited name "Files" should be deprecated and replaced by a new name "Folders"? Of course, folders are some special kind of files after all, so I am not sure.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: SelectDirectory dialog, how does Multi-select work?
« Reply #10 on: November 16, 2018, 05:56:12 pm »
RTFM and all that :)

Kinda rude and uncalled for.

I'm sorry if I have offended you;  I almost never answer a question with just a RTFM and this time it was, indeed, intended as nothing more than a tongue-in-cheek remark, complementary to the previous phrase, on wp's response--hence the afterwards smiley.
« Last Edit: November 16, 2018, 05:59:25 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

 

TinyPortal © 2005-2018