2011-05-06 76 views
4

似乎在Win7上更改TOpenDialog.InitialDir不起作用,当新目录位于与当前目录不同的驱动器上时。在Win7中更改Delphi OpenDialog +驱动器的目录

例如为:我要改变我的InitialDir'C:\program files\MyApp' to 'D:\test\MyAppData'

那是一个已知的问题,或者只是我的电脑上?

我已经尝试过同样的事情,在下面的文章中提到,但没有成功: Changing the directory of Delphi OpenDialog

编辑: 我对Win7的32位使用DelphiXE

的路径/ dir是正确的:因此,当我从代码中复制该路径并将其放到该对话框本身的“文件名”字段中并按ENTER时,则对话框切换到该目录。只有在我的代码中它不起作用。

更新:
我发现了这个问题。如果路径包含一些路径命令,如..\,则TOpenDialog.InitialDir无法解决该问题。使用TPath.GetFullPath(...)使其清洁。

回答

1

通过对象检查器或运行时(Win7 with Delphi 2010),我没有任何更改InitialDir的问题。如果您尝试更改的目录输入正确,请尝试重新检查。

2

我有一个Delphi XE测试,它运行良好...我已经做到了这一点:

把一种新的形式:

object Form4: TForm4 
    Left = 0 
    Top = 0 
    Caption = 'Form4' 
    ClientHeight = 204 
    ClientWidth = 447 
    Color = clBtnFace 
    Font.Charset = DEFAULT_CHARSET 
    Font.Color = clWindowText 
    Font.Height = -11 
    Font.Name = 'Tahoma' 
    Font.Style = [] 
    OldCreateOrder = False 
    PixelsPerInch = 96 
    TextHeight = 13 
    object Button1: TButton 
    Left = 24 
    Top = 40 
    Width = 75 
    Height = 25 
    Caption = 'Button1' 
    TabOrder = 0 
    OnClick = Button1Click 
    end 
    object Edit1: TEdit 
    Left = 120 
    Top = 42 
    Width = 121 
    Height = 21 
    TabOrder = 1 
    Text = 'D:\' 
    end 
    object OpenDialog1: TOpenDialog 
    InitialDir = 'C:\' 
    Left = 120 
    Top = 72 
    end 
end 

而且它的源代码:

unit Unit4; 

interface 

uses 
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
    Dialogs, StdCtrls; 

type 
    TForm4 = class(TForm) 
    OpenDialog1: TOpenDialog; 
    Button1: TButton; 
    Edit1: TEdit; 
    procedure Button1Click(Sender: TObject); 
    private 
    { Private declarations } 
    public 
    { Public declarations } 
    end; 

var 
    Form4: TForm4; 

implementation 

{$R *.dfm} 

procedure TForm4.Button1Click(Sender: TObject); 
begin 

    OpenDialog1.InitialDir := edit1.text; 
    OpenDialog1.Execute; 
end; 

end. 

Regards

+0

该OP特别要求将初始目录设置为不同的驱动器,您的DFM显示您正在请求'C:\' – 2011-05-06 07:00:42

+0

Hi @Cosmin Prund ....对不起,我不明白..我用'DFM-initialDir'测试了'C:\',但是当'Button1Click'执行时我已经测试过设置'edit1.text '到'D:\ and_folder'和相反。所有运行良好。 – ferpega 2011-05-06 07:05:33

+0

我的意思是,你可以用'OpenDialog1.InitialDir:='D:\ my_folder''来代替'OpenDialog1.InitialDir:= edit1.text;'并且所有工作都正常。我用3个磁盘和不同的文件夹测试了它,因为有一个'edit1'而不是一个常量字符串。 :-) – ferpega 2011-05-06 07:08:15