Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!



Share:
Notifications
Clear all

[Solved] Delphi (XE2) - Select directory dialog for OS X (Firemonkey)

1 Posts
1 Users
0 Reactions
2,101 Views
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2869
Topic starter  

I was creating an app for FireMonkey and needed to be able to select a directory, currently there is no method (that I could see) to do this. Here is what I used:

function SelectDirectory(const ATitle: string; var ADir: string): Boolean;
var
LOpenDir: NSOpenPanel;
LInitialDir: NSURL;
LDlgResult: NSInteger;
begin
Result := False;
LOpenDir := TNSOpenPanel.Wrap(TNSOpenPanel.OCClass.openPanel);
LOpenDir.setAllowsMultipleSelection(False);
LOpenDir.setCanChooseFiles(False);
LOpenDir.setCanChooseDirectories(True);
if ADir <> '' then
begin
LInitialDir := TNSURL.Create;
LInitialDir.initFileURLWithPath(NSSTR(ADir));
LOpenDir.setDirectoryURL(LInitialDir);
end;
if ATitle <> '' then
LOpenDir.setTitle(NSSTR(ATitle));
LOpenDir.retain;
try
LDlgResult := LOpenDir.runModal;
if LDlgResult = NSOKButton then
begin
ADir := string(TNSUrl.Wrap(LOpenDir.URLs.objectAtIndex(0)).relativePath.UTF8String);
Result := True;
end;
finally
LOpenDir.release;
end;
end;


   
ReplyQuote
Share: