0% found this document useful (0 votes)
232 views

Delphi Basics - SelectDirectory Command

The SelectDirectory function displays a dialog allowing the user to select a directory. There are two versions - the first displays a Windows browser dialog initialized to a specified start directory, while the second displays a different type of dialog that shows the files in the currently selected directory. The functions return a boolean indicating if the user selected or canceled the dialog, and update the chosen directory path if selected. Examples demonstrate using each version and displaying the result.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
232 views

Delphi Basics - SelectDirectory Command

The SelectDirectory function displays a dialog allowing the user to select a directory. There are two versions - the first displays a Windows browser dialog initialized to a specified start directory, while the second displays a different type of dialog that shows the files in the currently selected directory. The functions return a boolean indicating if the user selected or canceled the dialog, and update the chosen directory path if selected. Examples demonstrate using each version and displaying the result.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

11/1/2016

Delphi Basics : SelectDirectory command

DelphiBasics
SelectDirectory

Displayadialogtoallowuserselectionofadirectory

FileCtrlunit

Function

1 functionSelectDirectory(constCaption:stringconstStartDir:WideStringoutChosenDir:string):Boolean
2 functionSelectDirectory(varCurrDir:stringDialogOptions:TSelectDirOptsHelpContext:Longint):Boolean

Description
TheSelectDirectorydisplaysadialogallowingtheuserto
selectadirectoryChosenDirectory(drivepluspath).

Version1.

ThisdisplaysaWindowsbrowserdialog,initialisedtothe
specifiedStartDir.TheCaptiontextisshownatthetopofthe
dialog.

IftheuserpressesOK,thentheselecteddirectoryisreturned
intheChosenDirvariable,andthereturnvalueisTrue.

IftheuserpressesCancel,thennooutputisgiven,andthe
returnvalueisFalse.

Version2.

Thisdisplaysaverydifferenttypeofdialog,thatincidently
showsthefilesinthecurrentlyselecteddirectory.

TheCurrDirvalueisusedtopositionthedisplaytothegiven
directory,andisupdatedwiththeselectedvalueiftheuser
pressesOK.

TheDialogOptionsandHelpContextparametersarebeyond
thescopeofthisarticle.Theymaysafelybelefttodefault
values,asinthegivenexample.

Relatedcommands
ChDir
CreateDir
GetCurrentDir

Changetheworkingdrivepluspathfora
specifieddrive
Createadirectory
Getthecurrentdirectory(driveplus
directory)

http://www.delphibasics.co.uk/RTL.asp?Name=SelectDirectory

Examplecode:Lettheuserselectadialogusingthefirstversion

var
chosenDirectory:string
begin
//Asktheusertoselectarequireddirectory,startingwithC:
ifSelectDirectory('Selectadirectory','C:\',chosenDirectory)
thenShowMessage('Chosendirectory='+chosenDirectory)
elseShowMessage('Directoryselectionaborted')
end
Showfullunitcode

{DialogdisplaysuserselectsC:\ProgramFilesandhitsOK}

Chosendirectory=C:\ProgramFiles

Examplecode:Lettheuserselectadialogusingthesecondversion

var
options:TSelectDirOpts
chosenDirectory:string
begin
chosenDirectory:='C:\'//Setthestartingdirectory
//Asktheusertoselectusingacompletelydifferentdialog!
ifSelectDirectory(chosenDirectory,options,0)
thenShowMessage('Chosendirectory='+chosenDirectory)
elseShowMessage('Directoryselectionaborted')
end
Showfullunitcode

{DialogdisplaysuserselectsC:\ProgramFilesandhitsCancel}

1/3

11/1/2016

Delphi Basics : SelectDirectory command

GetDir

Getthedefaultdirectory(drivepluspath)
foraspecifieddrive
MkDir
Makeadirectory
RemoveDir
Removeadirectory
RmDir
Removeadirectory
SetCurrentDir
Changethecurrentdirectory
ForceDirectories Createanewpathofdirectories

Directoryselectionaborted

Authorlinks

BuyWebsiteTrafficat
Buywebsitetrafficexperts.com

BuyProxiesat
Buyproxies.io

DownloadthiswebsiteasaWindowsprogram.

http://www.delphibasics.co.uk/RTL.asp?Name=SelectDirectory

2/3

11/1/2016

Delphi Basics : SelectDirectory command

DelphiProgrammingNeilMoffatt20022016.Allrightsreserved.|Contacttheauthor|HomePage

http://www.delphibasics.co.uk/RTL.asp?Name=SelectDirectory

3/3

You might also like