[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Something like OpenDialog, but for a directory

Posted on 2002-03-19
19
Medium Priority
?
411 Views
Last Modified: 2010-04-05
Hi...
 When I click a button, I want my app to display an OpenDialog box similar to selecting a file, but for selecting a *directory* instead (only show directories, not files). How can I do this?

Thanks
   Shawn
0
Comment
Question by:aztec
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 3
  • +6
19 Comments
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 6881660
Hi Shawn,

Try this:

function GetPath: String;
var
 pl: PItemIDList;
 folder : array[0..MAX_PATH] of Char;
 bi  : TBrowseInfo;
begin
  Result := '';
  FillChar(bi,SizeOf(bi),#0);
  StrPCopy(Folder, PathEdit.Text);
  bi.pszDisplayName := @folder[0];
  bi.lpszTitle := 'Please Select a Folder';
  bi.ulFlags := BIF_RETURNONLYFSDIRS;
  bi.hwndOwner := ExportToParadoxForm.handle;
  pl := SHBrowseForFolder(bi);
  if Assigned(pl) then
    if SHGetPathFromIDList(pl, folder) then
      Result := Folder;
  CoTaskMemFree(pl);
end;

Hope this helps,

Cheers,

Stu.
0
 
LVL 6

Accepted Solution

by:
kotan earned 200 total points
ID: 6881748
Use this function

function SelectDirectory(const Caption: string; const Root: WideString; out Directory: string): Boolean; overload;
0
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 6881774
Kotan,

How?  What do I declare in Uses?  SelectDirectory doesn't even exist in the help file.  Can you give some more info?

Stu.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 6881784
My appologies, it does :)

That's a nice little function.  Looks like a wrapper for the code I posted above (which I got from Madshi I think from memory).

Speaking of which, I just noticed an error:

function GetPath: String;
var
pl: PItemIDList;
folder : array[0..MAX_PATH] of Char;
bi  : TBrowseInfo;
begin
 Result := '';
 FillChar(bi,SizeOf(bi),#0);
 StrPCopy(Folder, PathEdit.Text);
 bi.pszDisplayName := @folder[0];
 bi.lpszTitle := 'Please Select a Folder';
 bi.ulFlags := BIF_RETURNONLYFSDIRS;
 bi.hwndOwner := Form1.handle;
 pl := SHBrowseForFolder(bi);
 if Assigned(pl) then
   if SHGetPathFromIDList(pl, folder) then
     Result := Folder;
 CoTaskMemFree(pl);
end;

The Owner Handle was pointing to one of my forms.

Stu
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6881898
SelectDirectory already exists,
(or was it selectdir)
i guess its in the sysutils-unit

meikl ;-)
0
 
LVL 6

Expert Comment

by:kotan
ID: 6881910
SelectDirectory is in FileCtrl-unit
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6881914
yep, kotan
0
 
LVL 17

Expert Comment

by:inthe
ID: 6881928
the code stu posted is the nicest (IMHO) cause you can customize it by changing the TBrowseInfo structure.
add shlobj and activex to the uses for it to work.

also delete this line its not nessesary :
StrPCopy(Folder, PathEdit.Text);
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 6882273
listening
0
 
LVL 1

Expert Comment

by:Gerhard100198
ID: 6882476
Aztec,

Why don't you just make your own.
I've attached a unit file and a form file with the code.

Note:
1) This was done very quickly, you may want to enhance it.
2) When setting the directory of the dialog form make sure you send it the full path name, the path has to end with a file name (ex c:\temp\test.txt) or a directory ending with a "\" (ex. c:\temp\ )

Hope this helps

Gerhard

---Start unit (PAS) file----
unit Unit3;

interface

uses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls,
  Buttons, ExtCtrls, FileCtrl;

type
  TOKBottomDlg = class(TForm)
    OKBtn: TButton;
    CancelBtn: TButton;
    Bevel1: TBevel;
    DriveComboBox1: TDriveComboBox;
    DirectoryListBox1: TDirectoryListBox;
    procedure DriveComboBox1Change(Sender: TObject);
  private
    FDirectory: string;
    procedure SetDirectory(const Value: string);
    function GetDirectory: string;
    { Private declarations }
  public
    { Public declarations }
    property Directory: string read GetDirectory write SetDirectory;
  end;

var
  OKBottomDlg: TOKBottomDlg;

implementation

{$R *.DFM}

procedure TOKBottomDlg.DriveComboBox1Change(Sender: TObject);
begin
  DirectoryListBox1.Drive := DriveComboBox1.Drive;
end;

function TOKBottomDlg.GetDirectory: string;
begin
  Result := DirectoryListBox1.Directory;
end;

procedure TOKBottomDlg.SetDirectory(const Value: string);
begin
  FDirectory := Value;
  DriveComboBox1.Drive := ExtractFileDrive(FDirectory)[1];
  DirectoryListBox1.Directory := ExtractFilePath(FDirectory);
end;

end.
-----END UNIT FILE----

---START FORM (DFM) FILE----
object OKBottomDlg: TOKBottomDlg
  Left = 314
  Top = 244
  BorderStyle = bsDialog
  Caption = 'Dialog'
  ClientHeight = 214
  ClientWidth = 313
  Color = clBtnFace
  ParentFont = True
  OldCreateOrder = True
  Position = poScreenCenter
  PixelsPerInch = 96
  TextHeight = 13
  object Bevel1: TBevel
    Left = 8
    Top = 8
    Width = 297
    Height = 161
    Shape = bsFrame
  end
  object OKBtn: TButton
    Left = 79
    Top = 180
    Width = 75
    Height = 25
    Caption = 'OK'
    Default = True
    ModalResult = 1
    TabOrder = 0
  end
  object CancelBtn: TButton
    Left = 159
    Top = 180
    Width = 75
    Height = 25
    Cancel = True
    Caption = 'Cancel'
    ModalResult = 2
    TabOrder = 1
  end
  object DriveComboBox1: TDriveComboBox
    Left = 16
    Top = 16
    Width = 281
    Height = 19
    Anchors = [akLeft, akTop, akRight]
    TabOrder = 2
    OnChange = DriveComboBox1Change
  end
  object DirectoryListBox1: TDirectoryListBox
    Left = 16
    Top = 40
    Width = 281
    Height = 121
    ItemHeight = 16
    TabOrder = 3
  end
end
---END OF FORM FILE----
0
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 6884329
I guess the only reason I'd suggest using what I posted over a custom form is that it keeps the "windows" feel.  In other words, it looks like every other application's directory browser.

Thanks for pointing out the bit of code I left in there, Barry.  Oops :)

Stu
0
 
LVL 3

Expert Comment

by:SteveWaite
ID: 6884345
What about adding a callback to display the situation to the user?
0
 

Author Comment

by:aztec
ID: 6890053
Kotan - that works pretty nicely, thanks. Anyway to suppress the file listing somehow?

Maybe there's a 3rd party custom component out there that does this?

Thanks
  Shawn

0
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 6892603
aztec,

Did you try what I had posted?

Stu
0
 

Author Comment

by:aztec
ID: 6894880
No I didn't Stuart - Kotan's seemed like the quickie solution I was looking for. Yours will suppress the file listing?

Shawn
0
 

Author Comment

by:aztec
ID: 6894890
Can't find any info in Help under TBrowseInfo Stuart. Does it exist in Delphi 3 Pro?

Shawn
0
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 6895129
Aztec

It depends on how you code it.  The way I presented the code to you now displays a dialog box with directories only.  You can suppress or display the files if you wish by changing the TBrowseInfo flags.

Sometimes the quickest way isn't always the best way.

Stu
0
 
LVL 6

Expert Comment

by:kotan
ID: 6895487
Aztec,

Seem like there are 2 version of SelectDirectory(). One will show files and the other one is not.

Please refer below links
http://members.truepath.com/delphi/tips/tip105_selectdirectoryi1.htm
http://members.truepath.com/delphi/tips/tip106_selectdirectoryii1.htm
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6939340
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101 or Netminder will return to finalize these if still open in seven days.  Please post closing recommendations before that time.

Question(s) below appears to have been abandoned. Your options are:
 
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Click you Member Profile to view your question history and keep them updated as the collaboration effort continues, to maintain your open and locked questions.  If you are a  KnowledgePro user, use the Power Search option to find them.  Anytime you have questions which are LOCKED with a Proposed Answer which does not serve your needs, please reject it and add comments as to why.  In addition, when you do grade the question, if the grade is less than an A, please add a comment as to why.  This helps all involved, as well as future persons who may access this item for help.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.20245156.html
http://www.experts-exchange.com/questions/Q.20259219.html
http://www.experts-exchange.com/questions/Q.20263069.html
http://www.experts-exchange.com/questions/Q.20270808.html
http://www.experts-exchange.com/questions/Q.20269981.html
http://www.experts-exchange.com/questions/Q.20277592.html
http://www.experts-exchange.com/questions/Q.20279091.html


To view your locked questions, please click the following link(s) and evaluate the proposed answer.
http://www.experts-exchange.com/questions/Q.20263454.html
http://www.experts-exchange.com/questions/Q.20269773.html
http://www.experts-exchange.com/questions/Q.20279093.html

**** PLEASE DO NOT AWARD THE POINTS TO ME. *****
 
------------>  EXPERTS:  Please leave your closing recommendations if this item remains inactive another seven (7) days.  If you are interested in the cleanup effort, please click this link http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643 
POINTS FOR EXPERTS awaiting comments are listed here -> http://www.experts-exchange.com/commspt/Q.20277028.html
 

Moderators will finalize this question if in @7 days you have not responded.  They will either move this to the PAQ (Previously Asked Questions) at zero points, delete it or awarding expert(s) when recommendations are made, or an independent determination can be made.  Expert input is always appreciated to determine the fair outcome.
 
Thank you everyone.
 
Moondancer
Moderator @ Experts Exchange
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question