Você está na página 1de 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

Você também pode gostar