RAD Studio VCL Reference
|
Brings up a dialog to allow the user to enter a directory name.
function SelectDirectory(var Directory: string; Options: TSelectDirOpts; HelpCtx: Longint): Boolean; overload; function SelectDirectory(const Caption: string; const Root: WideString; var Directory: string; Options: TSelectDirExtOpts = [sdNewUI]; Parent: TWinControl = nil): Boolean; overload;
Boolean SelectDirectory(AnsiString Directory, TSelectDirOpts Options, Longint HelpCtx); Boolean SelectDirectory(const AnsiString Caption, const BSTR Root, AnsiString Directory, TSelectDirExtOpts Options = [sdNewUI], TWinControl * Parent = nil);
Call SelectDirectory to let the user enter a directory name.
Use the first syntax to call the Select Directory dialog box. The directory passed to the function with the Directory parameter appears as the currently selected directory when the dialog box appears. The name of the directory the user selects becomes the value of Directory when the function returns.
The HelpCtx parameter is the help context ID number.
Use the second syntax to display the Windows directory browser. The Caption parameter specifies a caption for the dialog. The Root parameter specifies the root directory from which to browse. The selected directory is returned as the Directory parameter. When using this syntax, SelectDirectory does not change the value of the current directory.
With either syntax, SelectDirectory returns true if the user selected a directory and chose OK, and false if the user chose Cancel or closed the dialog box without selecting a directory.
C++ Examples:
/* This example uses a button and a label on a form. When the user clicks the button, a Select Directory dialog box appears. The current directory displayed in the dialog box is C:\\Program Files\\CodeGear. The user can select a directory from the directory list, or enter a new directory in the edit box. If the user enters a new directory, a message box asks the user if the directory should be created. If the user chooses Yes, the directory is created. If the user chooses No, the message box goes away without creating the directory. The name of the directory the user selects appears as the caption of the label: */ #include "FileCtrl.hpp" const SELDIRHELP = 1000; void __fastcall TForm1::Button1Click(TObject *Sender) { String Dir = "C:\\Program Files\\CodeGear"; if (SelectDirectory(Dir, TSelectDirOpts() << sdAllowCreate << sdPerformCreate << sdPrompt,SELDIRHELP)) Label1->Caption = Dir; }
Delphi Examples:
{ This example uses a button and a label on a form. When the user clicks the button, a Select Directory dialog box appears. The current directory displayed in the dialog box is C:\WINDOWS. The user can select a directory from the directory list, or enter a new directory in the edit box. If the user enters a new directory, a message box asks the user if the directory should be created. If the user chooses Yes, the directory is created. If the user chooses No, the message box goes away without creating the directory. The name of the directory the user selects appears as the caption of the label: } uses FileCtrl; const SELDIRHELP = 1000; 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;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|