We help IT Professionals succeed at work.

Check out this week's podcast, "Dairy Farms to Databases: Community's Hand in Technology"Listen Now


Open Directory Dialog

dnote asked
Last Modified: 2010-04-06
Is there a simple way to create a dialog much like a standard Open/Save File Dialog, without having to create it as a component (I like to do this in OWL)
Watch Question


What do you mean by "simple way" and "without having to create it as a component"?
If I've understood your question, you could rather easily create a new empty form and drag components from the toolbar. There are FileListBox, DirectoryListBox, FilterComboBox and DriveComboBox that easily can be connected to each other by e.g. specifying the directory TLabel to be updated by the TDirectoryListBox, the file list (TListBox) to be updated by the TDirectoryListBox, etc.
Read the help for TDirectoryListBox and TDriveComboBox to find out more. It only takes 5-10 minutes to create such dialogs.


Dear ovj,
I do not want to use any components nor a form. I just wanna
use the standard dialogs in windows and change them so that
it becomes a directory dialog. In the help for API from Delphi
it says you can do something like this, but doesn't show any
examples on it. Under no circumstances I wanna use the Forms
unit !


If you do not want to use the forms unit or components I strongly suggest you stick to BP7 or C++ to work in windows since delphi's equivalent to the C++ OWL IS its components and the forms unit.

If you really want to do this the best will probably be to stick the file dialog calls in a dll that uses OWL calls, but this will get very nasty sizewise for your app.

The best advise I can give is to use the forms and the components provided unless you have a very good reason not to.

If you can provide such a reason I will gladly try to help you on this one ...


The reason is that I dont want my app to start at 160kB in size, with OWL I managed about 40kB, and I want to keep it round that size.

It IS possible to do OWL within delphi, look in delphi\source\rtl70 to find the source code.

The standard file open dialog does not allow for directory selection. You need to modify it using a dialog template resource. If you've experienced with "old-fashioned" windows programming, start looking at help for Win API function GetOpenFileName and friends. If not, you've got a problem ;)

I can't say anything besides that the size of the EXE is what you have to pay for using a RAD tool... If you've got D3, you could use the VCL30 dll instead of compiling it into your app, but it probably ain't any good with a 40k app relying on 1.3MB DLL....



Have a look at the files you have to ship with that 40k app of yours to allow it to work on a machine not running BC4 or similar. The OWL200.dll alone is 550k. If you are using BC4 you have to include bc40.dll, etc.

Compile your OWL app with all the libraries statically linked and you will end up with the same size app as with delphi.

The advantages of using .dll's are obvious, but an extra 100K in your app is not much considering the massive hard drives users have nowadays.

I wish all programmers were so concerned with keeping app size down. It seems to be a dying art nowadays !

Thus : Do as sperling says if you have to reduce the size. You are going to pay heavily with your time though ! Otherways jump in and follow the rest of us Delphi fans.

Use the GetOpenFileName Windows API call


Dont get me wrong, I AM a Delphi fan, but just with this program I wanted do it in old fashion windows programming way. I don't understand what you are meaning by those .dll's. My program doesn't require any. Maybe I've not been clear about a point, I am using just Delphi to compile the source in an equivalent way  like BP70 would. I'm caring about the program size because it is to be a Setup program, which in my opinion has to be relative small. What the GetOpenFileName concerns, it doesn't do the job, since I want to select a directory not a filename.
If anybody could send me some source with an example of a custom dialog template/hook, it would be greatly appreciated, the online help of delphi doesn't seem to dig very deep in the material.

I Think I might have an idea.  First of all, the dll's that are being talked about are the ones that get used behind your back.  If the EXE is thin, then its a safe bet that the dll it uses (maybe not explicitly) is sizable.

Anyhow, try this... In a dll (a unit with no form), declare a VAR of the type you want (VAR tt: TOpenDialog for example).  Then create an instance of that class:   tt := TOpenDialog.Create( NIL );  Then use the dialog with  tt.Execute.  Of course, you wrap all of this in a procedure that you export from the dll and call from an external program (like your setup pgm).

Dont forget to free to object when your done!  Also, enclose the whole thing in a TRY EXCEPT to keep any exceptions from escaping the dll.

Hope this helps.  (I have not tried this by the way, but I will tonite).


Well, for directories, use the SHBrowseForFolder API call.


The opendialog implements the openfilename dialog, not a directory dialog...

SHBrowseForFolder ??? Where is it ?
This one is on us!
(Get your first solution completely free - no credit card required)


Bingo !!!

Actually the answer from msnell is not that bad either - SHBrowseForFolder is available in ShlObj.pas (Delphi 3).

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.