Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/VCL/Dialog Controls    [ Add a report in this area ]  
Report #:  106407   Status: Open
[Vista/Windows Server 2008] Wrong folder is returned from TFileOpenDialog with fdoPickFolders option
Project:  Delphi Build #:  2010, ... XE2
Version:    16.4 Submitted By:   Ralph Gielkens
Report Type:  Basic functionality failure Date Reported:  6/14/2012 1:46:30 AM
Severity:    Serious / Highly visible problem Last Updated: 6/27/2012 8:13:49 PM
Platform:    All versions Internal Tracking #:   29055
Resolution: None (Resolution Comments) Resolved in Build: : None
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: 1
Description
Added by Sysop
<<<<<
Please see [Comments] of QC for more details.
>>>>>

OS is 'Vista' or 'Windows Server 2008'.

There is a bug with the class TFileOpenDialog on Windows Server 2008, the wrong folder is selected.
------
      FileOpenBox.Options := FileOpenBox.Options + [fdoPickFolders];
------

On other operating systems(Windows Server 2008 R2), it works correctly.

When I select a folder named:
c:\Temp\in
the property "FileOpenBox.FileName" returns:
c:\Temp\in\in

When I clear the Folder in the dialog, the result is correctly.

Do you know a workaround, without using a other object??
Steps to Reproduce:
0. OS is 'Vista' or 'Windows Server 2008'.

1. Create a test project and add a button

2. add this code:
-----------------
procedure TForm1.Button1Click(Sender: TObject);
var
  FileOpenBox  : TFileOpenDialog;
begin
  if (Win32MajorVersion >= 6) then
  begin
    FileOpenBox := TFileOpenDialog.Create(nil);
    try
      FileOpenBox.Title := 'Select Directory';
      FileOpenBox.DefaultFolder := 'c:\temp\';
      FileOpenBox.Options := FileOpenBox.Options + [fdoPickFolders];
      FileOpenBox.OkButtonLabel := 'Select';

      if FileOpenBox.Execute then
      begin
        ShowMessage ('Folder selected: ' + FileOpenBox.FileName);
      end;
    finally
      FreeAndNil(FileOpenBox);
    end;
  end;
end;
-----------------

3. If I just select c:\Temp folder in the dialog and press ok, I get c:\temp.

4. But, if I double click c:\Temp folder in the dialog and press ok, I get c:\temp\temp. In this case, string 'temp' is entered in Text filed of the dialog. So, if I clear the field and press ok, I get c:\temp.
Workarounds
Please try my workaround as below.
------------------------
uses Winapi.ShlObj;

type
  TFileOpenDialog = class(Vcl.Dialogs.TFileOpenDialog)
  public
    folder: TFileName;
  strict protected
    function GetResults: HResult; override;
  end;

{ TFileOpenDialog }

function TFileOpenDialog.GetResults: HResult;
var
  ppsi: IShellItem;
begin
  Result := inherited;
  if Succeeded(Dialog.GetFolder(ppsi)) then
  begin
    if not Succeeded(GetItemName(ppsi, folder)) then
      folder := '';
  end;
  ppsi := nil;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  FileOpenBox  : TFileOpenDialog;
begin
  if (Win32MajorVersion >= 6) then
  begin
    FileOpenBox := TFileOpenDialog.Create(nil);
    try
      FileOpenBox.Title := 'Select Directory';
      FileOpenBox.DefaultFolder := 'c:\temp\';
      FileOpenBox.Options := FileOpenBox.Options + [fdoPickFolders];
      FileOpenBox.OkButtonLabel := 'Select';

      if FileOpenBox.Execute then
      begin
        //ShowMessage ('Folder selected: ' + FileOpenBox.FileName);
        ShowMessage ('Folder selected: ' + FileOpenBox.folder);
      end;
    finally
      FreeAndNil(FileOpenBox);
    end;
  end;
end;
------------------------
Attachment
None
Comments

Tomohiro Takahashi at 6/14/2012 9:01:43 PM -
> Build No: 14
What version(and build no) of Delphi do you use, for example Delphi 2010 Update 4,5(14.0.3593.25826)?

>       FileOpenBox.DefaultFolder := TJvDirectoryEdit(sender).Text;
Could you please attach simple sample project(without 3rd-party components) to reproduce/verify your issue?

Ralph Gielkens at 6/15/2012 2:40:51 AM -
The build is 14.0.3593.25826
I've also tried it with XE2 and the same problem occurs.

Sorry about that. I've included the FileOpenDialog.zip

Ralph Gielkens at 6/15/2012 2:44:55 AM -
it's not possible to add a zip file so here is the code without third party components.

procedure TForm1.Button1Click(Sender: TObject);
var
  FileOpenBox  : TFileOpenDialog;
begin
  if (Win32MajorVersion >= 6) then
  begin
    FileOpenBox := TFileOpenDialog.Create(nil);
    try
      FileOpenBox.Title := 'Select Directory';
      FileOpenBox.DefaultFolder := 'c:\temp\';
      FileOpenBox.Options := FileOpenBox.Options + [fdoPickFolders];
      FileOpenBox.OkButtonLabel := 'Select';

      if FileOpenBox.Execute then
      begin
        ShowMessage ('Folder selected: ' + FileOpenBox.FileName);
      end;
    finally
      FreeAndNil(FileOpenBox);
    end;
  end;
end;

Tomohiro Takahashi at 6/15/2012 5:51:49 AM -
Could you please use Windows Native QC Client to attach a .zip file to this report?
The standalone client comes with Delphi.

Tomohiro Takahashi at 6/15/2012 10:57:23 PM -
> When I select a folder named:
> c:\Temp\in
I tested your code in Vista and Windows 2008 SP2 32bit.
If I just select c:\Temp folder in the dialog and press ok, I get c:\temp.
But, if I double click c:\Temp folder in the dialog and press ok, I get c:\temp\temp. In this case, string 'temp' is entered in Text filed of the dialog. So, if I clear the field and press ok, I get c:\temp.

Tomohiro Takahashi at 6/15/2012 11:51:52 PM -
Please try my workaround as below.
------------------------
uses Winapi.ShlObj;

type
  TFileOpenDialog = class(Vcl.Dialogs.TFileOpenDialog)
  public
    folder: TFileName;
  strict protected
    function GetResults: HResult; override;
  end;

{ TFileOpenDialog }

function TFileOpenDialog.GetResults: HResult;
var
  ppsi: IShellItem;
begin
  Result := inherited;
  if Succeeded(Dialog.GetFolder(ppsi)) then
  begin
    if not Succeeded(GetItemName(ppsi, folder)) then
      folder := '';
  end;
  ppsi := nil;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  FileOpenBox  : TFileOpenDialog;
begin
  if (Win32MajorVersion >= 6) then
  begin
    FileOpenBox := TFileOpenDialog.Create(nil);
    try
      FileOpenBox.Title := 'Select Directory';
      FileOpenBox.DefaultFolder := 'c:\temp\';
      FileOpenBox.Options := FileOpenBox.Options + [fdoPickFolders];
      FileOpenBox.OkButtonLabel := 'Select';

      if FileOpenBox.Execute then
      begin
        //ShowMessage ('Folder selected: ' + FileOpenBox.FileName);
        ShowMessage ('Folder selected: ' + FileOpenBox.folder);
      end;
    finally
      FreeAndNil(FileOpenBox);
    end;
  end;
end;
------------------------

Ralph Gielkens at 6/26/2012 2:25:52 AM -
Sorry I had vacation, I added the code and the problem isn't solved. I double click on a folder and I only click once on the select button.

Tomohiro Takahashi at 6/26/2012 7:27:49 PM -
I can reproduce and resolve your issue with my code.

Please makre sure that new member is used as below.
...
        //ShowMessage ('Folder selected: ' + FileOpenBox.FileName);
        ShowMessage ('Folder selected: ' + FileOpenBox.folder);
...

Ralph Gielkens at 6/27/2012 12:53:29 AM -
Sorry, this is my mistake. I forgot to change this. This works.
Thanks.

Tomohiro Takahashi at 6/18/2012 5:20:04 PM -
This report was opened with valid Internal Tracking Number.
Thanks.

Server Response from: ETNACODE01