DELPHI - How to use opendialog1 for choosing a folder? TOpenDialog, TFileOpenDialog

时间:2022-12-31 08:12:20

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 + '\';

DELPHI - How to use opendialog1 for choosing a folder? TOpenDialog, TFileOpenDialog

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:

DELPHI - How to use opendialog1 for choosing a folder? TOpenDialog, TFileOpenDialog

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 处理图片&lpar;剪切,压缩&rpar;

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

  6. Delphi如何打开DBF数据库

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

  7. Delphi ServerSocket&comma;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. Trick蠕虫病毒来袭!幕后主使竟是一名高中生&OpenCurlyDoubleQuote;黑客”!

    黑客一直是美国电影中的重要元素,很多经典大片中都有黑客的身影,如战争游戏.黑客帝国等.电影中黑客总是神通广大.行侠仗义,<战争游戏>中的年轻黑客大卫•莱特曼利用黑客技术避免引爆核武器,&l ...

  2. iOS 键盘类型

    版权声明:本文为博主原创文章.请尊重作者劳动成果,转载请注明出处. UIKeyboardTypeDefault: UIKeyboardTypeASCIICapable: UIKeyboardTypeN ...

  3. ubuntu --- shortcut key

    Linux系统下图形界面与Linux命令行模式的切换的方法 由图形转换到控制台模式:ctrl+alt+f1~f6(同时按下3秒钟不要马上松开)....由控制台转向图形模式是:alt+f7 快捷键(ub ...

  4. css如何实现多行文本时&comma;内容溢出&comma;出现省略号

    一:单行文本出现省略号: .oneLine{ white-space: nowrap; text-overflow: ellipsis; overflow: hidden; width: 100px; ...

  5. Open quote is expected for attribute &quot&semi;property&quot&semi; associated with an element type &quot&semi;result&quot&semi;&period;错误

    java  Mybatis 框架下的项目 报   Open quote is expected for attribute "property" associated with a ...

  6. Codeforces Round &num;372 &lpar;Div&period; 2&rpar; A

    Description ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecut ...

  7. input子系统 KeyPad-Touch上报数据格式与机制

    -----------------------------------------------------------------------本文系本站原创,欢迎转载!转载请注明出处:http://b ...

  8. Plan-9效应:为什么东西不坏就不要去修它

    http://www.aqee.net/the-plan-9-effect-or-why-you-should-not-fix-it-if-it-aint-broken/ Plan-9是一个很棒的.很 ...

  9. Linux下的数据监控工具

    Vmstat Vmstat,virtual memmory statistics(虚拟内存统计),主要是对操作系统的内存信息.进程状态.cpu活动等进行监视,但是它不能对某个进程进行深入的分析. Pr ...

  10. Educational Codeforces Round 20&period;C

    C. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard input ...