Incus J 10 Posted April 23, 2021 (edited) Does Delphi 10.4 FMX have a built in routine or component to display a Choose a Folder dialog? I can see dialog components to open and save a file, but not to select a folder. If there isn't anything built in, how might I achieve this? I'm looking for something that will work on both Windows and macOS. I have found some code online, and the Windows side of it works, but it looks fairly elaborate, and the macOS code crashes the app with Exception class 6. So perhaps there is an easier approach using existing routines. I'm running 10.4 Update 1 at present. Edited April 23, 2021 by Incus J Share this post Link to post
Remy Lebeau 1398 Posted April 23, 2021 4 hours ago, Incus J said: Does Delphi 10.4 FMX have a built in routine or component to display a Choose a Folder dialog? No. 4 hours ago, Incus J said: If there isn't anything built in, how might I achieve this? IFDEF your code to call the relevant OS APIs directly (SHBrowseForFolder()/IFileOpenDialog on Windows, etc). Or else just make your own dialog/Form that iterates the filesystem (ie, via the System.IOUtils.TDirectory class) and display the contents as needed. 1 Share this post Link to post
Wil van Antwerpen 25 Posted April 23, 2021 Hi, I'm basically using the following: http://www.fmxexpress.com/select-directory-dialogs-in-delphi-xe8-firemonkey-on-windows-and-osx/ Just a little tweaked. -- Wil 1 Share this post Link to post
f.m 8 Posted April 25, 2021 (edited) Perhaps SelectDirectory() from FMX.Dialogs could be beneficial. It is implemented for Windows and macOS platforms. It is not implemented for Android nor iOS. var LDirectory : String; if SelectDirectory('Test' {Title}, '' {Root}, LDirectory {out}) then begin // selected.. ShowMessage(LDirectory); end; Edited April 25, 2021 by f.m 2 1 Share this post Link to post
Incus J 10 Posted April 26, 2021 Thank you Remy, Wil, f.m, The code I found online is the same fmxexpress example Wil mentions above, so I've been playing around with it. If I comment out the following block, then it works without crashing the app: if ADir <> '' then begin LInitialDir := TNSURL.Create; LInitialDir.initFileURLWithPath(NSSTR(ADir)); LOpenDir.setDirectoryURL(LInitialDir); end; The crash was occurring on LInitialDir.initFileURLWithPath(NSSTR(ADir)); and when I stepped through the code ADir appeared to be '' empty, so I'm not sure how this block was executing at all. I guess without this block I'm losing the capability for specifying an initial starting folder. I also get a warning that NSSTR is deprecated, but the suggested replacement StrToNSStr is not recognised. Is there an easy way to query which system unit a function might be in? Share this post Link to post
Incus J 10 Posted April 26, 2021 FMX.Dialogs function SelectDirectory(const Caption: string; const Root: string; var Directory: string): Boolean; Thank you f.m - that's exactly what I'm looking for! Share this post Link to post
Wil van Antwerpen 25 Posted April 26, 2021 15 minutes ago, Incus J said: I also get a warning that NSSTR is deprecated, but the suggested replacement StrToNSStr is not recognised. Is there an easy way to query which system unit a function might be in? Hi, I have that same code and don't see a crash, not sure what else is different. re. the StrtoNSStr, you have to use the correct module for it to be recognized. If I'm not mistaken it is in: Macapi.Helpers, re. suggestion from f.m. thanks for the tip, I will check it out. Share this post Link to post
skyzoframe[hun] 4 Posted April 22, 2023 (edited) Now it has. https://docwiki.embarcadero.com/CodeExamples/Alexandria/en/SelectDirectory_(Delphi) Edited April 22, 2023 by skyzoframe[hun] Share this post Link to post