Главная страница | назад





Article #28451: How can I use a dialog window to have a user select a folder without a file name?

QUESTION:


How can I use a dialog window to have a user select a folder without a file name?


ANSWER:


You can accomplish this without using a TOpenDialog component. First, add FileCtrl to the Uses. Now the SelectDirectory function can be used. Drop a TButton component on your Form. Place the following code in the button's onClick event to get a demonstration of how this function works:

procedure TForm1.Button1Click(Sender: TObject);
const
SELDIRHELP = 1000;
var
dir: String;
begin
dir := 'C:';
if SelectDirectory(dir, [sdAllowCreate, sdPerformCreate, sdPrompt],SELDIRHELP) then
Button1.Caption := dir;
end;

For an explanation of the parameters that SelectDirectory takes, look up the function inside Delphi Help.

Last Modified: 28-FEB-02