Link to home
Start Free TrialLog in
Avatar of aztec
aztec

asked on

Problem with SelectDirectory Function

Hi...
  When the user calls the SelectDirectory function in my app, I want it to default to the root directory (ie. C:\)... but it won't do it. Here's my code:

defdir:='c:\';
if SelectDirectory(defdir,[],0) then
   speedbutton21.hint:=defdir
else speedbutton21.hint:='';

...the SelectDirectory dialog box always comes up with the directory my app is located in, as its selected directory...weird. There seems to be no way I can force it to go to the root directory.

Any thoughts?

Thanks
   Shawn
Avatar of alanwhincup
alanwhincup

You could do it like this:

procedure TForm1.Button1Click(Sender: TObject);
var
  DefDir : string;
begin
  if SelectDirectory('Please choose a directory:', 'C:\', DefDir) then
    speedbutton21.hint := DefDir
  else
    speedbutton21.hint := '';
end;
ASKER CERTIFIED SOLUTION
Avatar of Jacco
Jacco
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of aztec

ASKER

that gives a complile error:

"Constant object cannot be passed as var parameter"

I don't think it likes the 'Please choose a directory'...it's expecting a variable.

Shawn