重複の可能性:
Delphi:TOpenDialogでディレクトリを選択
プロジェクトで特定のフォルダを開く必要があります。opendialog1を使用すると、ファイルしか開くことができません。フォルダを開いてみませんか?
PS:私はDelphi2010を使用しています
重複の可能性:
Delphi:TOpenDialogでディレクトリを選択
プロジェクトで特定のフォルダを開く必要があります。opendialog1を使用すると、ファイルしか開くことができません。フォルダを開いてみませんか?
PS:私はDelphi2010を使用しています
Vista以降では、を使用してよりモダンなダイアログを表示できます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;
これは次のようになります:
SelectDirectory
あなたはFileCtrl
ユニットで探しています。2つのオーバーロードされたバージョンがあります。
function SelectDirectory(var Directory: string;
Options: TSelectDirOpts; HelpCtx: Longint): Boolean;
function SelectDirectory(const Caption: string; const Root: WideString;
var Directory: string; Options: TSelectDirExtOpts; Parent: TWinControl): Boolean;
使用するものは、使用しているDelphiのバージョン、および探している特定の外観と機能によって異なります。私(通常、2番目のバージョンはDelphiとWindowsの最新バージョンで完全に機能し、ユーザーは「通常期待される外観と機能」に満足しているようです。
TBrowseForFolder
アクションクラス(stdActns.pas
)を使用することもできます。
var
dir: string;
begin
with TBrowseForFolder.Create(nil) do try
RootDir := 'C:\';
if Execute then
dir := Folder;
finally
Free;
end;
end;
または、WinApi関数SHBrowseForFolder
を直接使用します(SelectDirectory
実行時にすべてのコントロールを備えた独自のデルファイウィンドウを作成する最初のオーバーロードの代わりに、2番目のオーバーロードがそれを使用します):
var
dir : PChar;
bfi : TBrowseInfo;
pidl : PItemIDList;
begin
ZeroMemory(@bfi, sizeof(bfi));
pidl := SHBrowseForFolder(bfi);
if pidl <> nil then try
GetMem(dir, MAX_PATH + 1);
try
if SHGetPathFromIDList(pidl, dir) then begin
// use dir
end;
finally
FreeMem(dir);
end;
finally
CoTaskMemFree(pidl);
end;
end;