DELPHI - How to use opendialog1 for choosing a folder? TOpenDialog, TFileOpenDialog
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的更多相关文章
- 学习笔记:7z在delphi的应用
最近做个发邮件的功能,需要将日志文件通过邮件发送回来用于分析,但是日志文件可能会超级大,测算下来一天可能会有800M的大小.所以压缩是不可避免了,delphi中的默认压缩算法整了半天不太好使,就看了看 ...
- Delphi 操作Flash D7~XE10都有 导入Activex控件 shockwave
http://www.cnblogs.com/devcjq/articles/2906224.html Flash是Macromedia公司出品的,用在互联网上动态的.可互动的shockwave.它的 ...
- Delphi编程获取系统当前进程、窗口句柄、文件属性以(转)
Delphi编程获取系统当前进程.窗口句柄.文件属性以及程序运行状态. uses TLHelp32,PsAPI; (1)显示进程列表:procedure TForm1.Button2Click(Sen ...
- Delphi Excel 操作大全
Delphi Excel 操作大全 (一) 使用动态创建的方法首先创建 Excel 对象,使用ComObj:var ExcelApp: Variant;ExcelApp := CreateOleObj ...
- delphi 处理图片(剪切,压缩)
剪切bmp:效果为指定的rect大小,若图片比rect小,则会放大. 都要uses Vcl.Imaging.jpeg; 需要注意的是FMX里也需要jpeg的支持,虽然没引用编译器不会报错,但用到jpg ...
- Delphi如何打开DBF数据库
Delphi语言,无论Delphi7.Delphi2007或者Delphi XE2或3,无需安装其它附加的部件,就可以实现DBF文件的打开及相关操作,网络上很多要用到什么ADO引擎的,其实未必,只有安 ...
- Delphi ServerSocket,ClientSocket示例
Delphi ServerSocket,ClientSocket示例 2008-05-09 16:20 Delphi TServerSocket,TClientSocket实现传送文件代码 1.建立两 ...
- Delphi摄像头操作
/*Title:Delphi摄像头操作 *Author:Insun *Blog:http://yxmhero1989.blog.163.com *From:www.4safer.com */ 为了笔耕 ...
- 奖学金评分系统(系统分析与设计版与Delphi实现代码)
一.系统规划 1.1 项目背景介绍 在奖学金评比过程中,学生综合测评是学校普遍采用的评比手段.对学生实施综合素质测评的目的在于正确评价学生的综合素质,为评奖学金提供依据,实现学生教育管理工作的标准化. ...
随机推荐
- javascript的this分别代表什么
鉴于大家对this到底代表的是什么有疑问,现在将我个人理解的this的情况整理如下.有错误请指正. 第一种情况: 如果是一个全局的function,则this相当于window对象. 这个打印出来的 ...
- linux下如何模拟按键输入和模拟鼠标【转】
转自:http://www.cnblogs.com/leaven/archive/2010/11/30/1891947.html 查看/dev/input/eventX是什么类型的事件, cat /p ...
- nc用法【转】
linux nc命令使用详解 功能说明:功能强大的网络工具 语 法:nc [-hlnruz][-g<网关...>][-G<指向器数目>][-i<延迟秒数>][-o& ...
- python里面的引用
1 对象及其引用 python中,引用是用命名空间来实现的,命名空间维护了变量和对象之间的引用关系. myInt = 27 yourInt = myInt #change the value of y ...
- ubuntu16。04LST配置nfs实现服务器和客户端共享文件
NFS(network file system)网络文件系统可以实现不同主机与操作系统之间通过网络进行资源共享,此时一台PC充当服务器,若干台PC充当那客户端,具体如何配置请跟随我的步骤来做 1 下载 ...
- 洛谷P3375KMP字符串匹配
传送门 #include <iostream> #include <cstdio> #include <cstring> #include <algorith ...
- 【LOJ】#6436. 「PKUSC2018」神仙的游戏
题解 感觉智商为0啊QAQ 显然对于一个长度为\(len\)的border,每个点同余\(n - len\)的部分必然相等 那么我们求一个\(f[a]\)数组,如果存在\(s[x] = 0\)且\(s ...
- 【AtCoder】AGC021
A - Digit Sum 2 从高位到低位数的第i位以前前缀都相同,第i位比当前位上的数小1的情况下,后面都填9 枚举一下然后计算最大的就好 #include <bits/stdc++.h&g ...
- 【BZOJ】1294: [SCOI2009]围豆豆Bean
题解 随机跳题真好玩 这个就是考虑我们怎么判断点在多边形内,就是点做一条射线,穿过了奇数条边 我们只需要记录一个二进制状态表示每个点的射线穿过路径的次数的奇偶性 枚举起点,然后用BFS的方式更新dp状 ...
- Python3 CNN中卷积和池化的实现--限制为二维输入
# -*- coding: utf-8 -*- """ Created on Wed Jan 31 14:10:03 2018 @author: markli " ...