DELPHI - How to use opendialog1 for choosing a folder?

On Vista and up you can show a more modern looking dialog using TFileOpenDialog.

var
OpenDialog: TFileOpenDialog;
SelectedFolder: string;
.....
OpenDialog := TFileOpenDialog.Create(MainForm);
try
OpenDialog.Options := OpenDialog.Options + [fdoPickFolders];
if not OpenDialog.Execute then
Abort;
SelectedFolder := OpenDialog.FileName;
finally
OpenDialog.Free;
end; if SelectedFolder[ Length( SelectedFolder ) ] <> '\' then
SelectedFolder := SelectedFolder + '\';

uses FileCtrl;
const
SELDIRHELP = ;
procedure TForm1.Button1Click(Sender: TObject);
var
Dir: string;
begin
Dir := 'C:\Windows';
if FileCtrl.SelectDirectory(Dir, [sdAllowCreate, sdPerformCreate, sdPrompt],SELDIRHELP) then
Label1.Caption := Dir;
end;

Selecting a directory with TOpenDialog

ust found the code below that seems to work fine in XP and Vista, Win7.

It provides a UI for a user to select a directory.

It uses TOpenDialog, but sends it a few messages to clean up the appearance for the purposes of selecting a directory.

After suffering from the limited capabilities provided by Windows itself,

it's a pleasure to be able to give my users a familiar UI where they can browse and select a folder comfortably.

I'd been looking for something like this for a long time so thought I'd post it here so others can benefit from it.

Here's what it looks like in Win 7:

function GimmeDir(var Dir: string): boolean;
var
OpenDialog: TOpenDialog;
OpenDir: TOpenDir;
begin
//The standard dialog...
OpenDialog:= TOpenDialog.Create(nil);
//Objetc that holds the OnShow code to hide controls
OpenDir:= TOpenDir.create;
try
//Conect both components...
OpenDir.Dialog:= OpenDialog;
OpenDialog.OnShow:= OpenDir.HideControls;
//Configure it so only folders are shown (and file without extension!)...
OpenDialog.FileName:= '*.';
OpenDialog.Filter:= '*.';
OpenDialog.Title:= 'Chose a folder';
//No need to check file existis!
OpenDialog.Options:= OpenDialog.Options + [ofNoValidate];
//Initial folder...
OpenDialog.InitialDir:= Dir;
//Ask user...
if OpenDialog.Execute then begin
Dir:= ExtractFilePath(OpenDialog.FileName);
result:= true;
end else begin
result:= false;
end;
finally
//Clean up...
OpenDir.Free;
OpenDialog.Free;
end;
end;

DELPHI - How to use opendialog1 for choosing a folder? TOpenDialog, TFileOpenDialog的更多相关文章

  1. 学习笔记:7z在delphi的应用

    最近做个发邮件的功能,需要将日志文件通过邮件发送回来用于分析,但是日志文件可能会超级大,测算下来一天可能会有800M的大小.所以压缩是不可避免了,delphi中的默认压缩算法整了半天不太好使,就看了看 ...

  2. Delphi 操作Flash D7~XE10都有 导入Activex控件 shockwave

    http://www.cnblogs.com/devcjq/articles/2906224.html Flash是Macromedia公司出品的,用在互联网上动态的.可互动的shockwave.它的 ...

  3. Delphi编程获取系统当前进程、窗口句柄、文件属性以(转)

    Delphi编程获取系统当前进程.窗口句柄.文件属性以及程序运行状态. uses TLHelp32,PsAPI; (1)显示进程列表:procedure TForm1.Button2Click(Sen ...

  4. Delphi Excel 操作大全

    Delphi Excel 操作大全 (一) 使用动态创建的方法首先创建 Excel 对象,使用ComObj:var ExcelApp: Variant;ExcelApp := CreateOleObj ...

  5. delphi 处理图片(剪切,压缩)

    剪切bmp:效果为指定的rect大小,若图片比rect小,则会放大. 都要uses Vcl.Imaging.jpeg; 需要注意的是FMX里也需要jpeg的支持,虽然没引用编译器不会报错,但用到jpg ...

  6. Delphi如何打开DBF数据库

    Delphi语言,无论Delphi7.Delphi2007或者Delphi XE2或3,无需安装其它附加的部件,就可以实现DBF文件的打开及相关操作,网络上很多要用到什么ADO引擎的,其实未必,只有安 ...

  7. Delphi ServerSocket,ClientSocket示例

    Delphi ServerSocket,ClientSocket示例 2008-05-09 16:20 Delphi TServerSocket,TClientSocket实现传送文件代码 1.建立两 ...

  8. Delphi摄像头操作

    /*Title:Delphi摄像头操作 *Author:Insun *Blog:http://yxmhero1989.blog.163.com *From:www.4safer.com */ 为了笔耕 ...

  9. 奖学金评分系统(系统分析与设计版与Delphi实现代码)

    一.系统规划 1.1 项目背景介绍 在奖学金评比过程中,学生综合测评是学校普遍采用的评比手段.对学生实施综合素质测评的目的在于正确评价学生的综合素质,为评奖学金提供依据,实现学生教育管理工作的标准化. ...

随机推荐

  1. java CyclicBarrier以及和CountDownLatch的区别

    CyclicBarrier 的字面意思是可循环使用(Cyclic)的屏障(Barrier).让一组线程到达一个屏障(也可以叫同步点)时被阻塞,直到最后一个线程到达屏障时,屏障才会开门,所有被屏障拦截的 ...

  2. 20145234黄斐《Java程序设计》第八周

    教材学习内容总结 第十四章-NIO与NIO2 NIO与IO的区别 NIO Channel继承框架 想要取得Channel的操作对象,可以使用Channels类,它定义了静态方法newChannel() ...

  3. 【Python】exe2shellcode,shellcode2exe

    用python写这类程序真简洁,要是用C++又不知道得多写多少行代码了. exe2shellcode #! /usr/bin/env python # -*- coding: utf-8 -*- im ...

  4. springcloud常见问题处理

    无法在任何已知服务器上执行请求. 原因是注册中心未启动.在使用springcloud搭建微服务时,一定要先启动注册中心,再启动服务端和客户端.具体报错如下: com.netflix.discovery ...

  5. Hibernate 二级缓存疑难点

    一级缓存:缓存实体 二级缓存:缓存实体 Hibernate查询缓存缓存的是查询出来的实体的部分属性结果集和实体的ID(注意这里不是实体). Hibernate查询缓存:对List起作用.但是Hiber ...

  6. 不使用第三方软件、使用IE11自带功能来屏蔽浏览器广告

    第一步: 下载后面的附件http://files.cnblogs.com/limits/IE11%E5%8E%BB%E5%B9%BF%E5%91%8A.zip 打开此路径IE11跟踪保护+CSS去广告 ...

  7. [转]mysql性能优化-慢查询分析、优化索引和配置

    一. 优化概述 MySQL数据库是常见的两个瓶颈是CPU和I/O的瓶颈,CPU在饱和的时候一般发生在数据装入内存或从磁盘上读取数据时候.磁盘I/O瓶颈发生在装入数据远大于内存容量的时候,如果应用分布在 ...

  8. Session,Token相关区别

    1. 为什么要有session的出现?答:是由于网络中http协议造成的,因为http本身是无状态协议,这样,无法确定你的本次请求和上次请求是不是你发送的.如果要进行类似论坛登陆相关的操作,就实现不了 ...

  9. mac zsh环境配置java_home环境变量

    用zsh,修改-/.zshrc 修改这些文件之后,重修打开terminal,配置不会丢 首先确保已经安装了jdk: ## check the present running java which ja ...

  10. Reactor模型-单线程版

    Reactor模型是典型的事件驱动模型.在网络编程中,所谓的事件当然就是read.write.bind.connect.close等这些动作了.Reactor模型的实现有很多种,下面介绍最基本的三种: ...