更改 Delphi OpenDialog 的目录 + Win7下驱动

发布于 2024-11-06 01:49:28 字数 671 浏览 0 评论 0原文

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

例如:我想将我的 InitialDir'C:\program files\MyApp' 更改为 'D:\test\MyAppData'

这是一个已知问题,还是仅在我的电脑?

我已经尝试过同样的事情,如以下帖子中所述,但没有成功: 更改 Delphi OpenDialog 的目录

编辑: 我在 Win7 32 位上使用 DelphiXE

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

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

It seems that on Win7 changing the TOpenDialog.InitialDir doesn't work, when the new directory is on a different drive, than the current directory.

e.g.: I want to change my InitialDir from 'C:\program files\MyApp' to 'D:\test\MyAppData'

Is that a known issue, or only on my computer?

I already tried the same thing, as mentioned in the following post, but without any success:
Changing the directory of Delphi OpenDialog

EDIT:
I am using DelphiXE on Win7 32 Bit

The path/dir is correct: So, when I copy that path from code and past it into the 'File Name' field of that Dialog itself and I press ENTER, then the Dialog switches to that directory. Only, in my code it is not working.

UPDATE:
I found the problem. If the path contains some path commands like ..\ the TOpenDialog.InitialDir is not able to resolve that. Use TPath.GetFullPath(...) to make it clean.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦在深巷 2024-11-13 01:49:28

我已经在 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.

问候

I have tested on a Delphi XE, it runs fine... I have done this:

Put a new form:

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

And its source code:

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

旧时浪漫 2024-11-13 01:49:28

我在更改 InitialDir 时没有任何问题,无论是通过对象检查器还是运行时(Win7 和 Delphi 2010)。尝试仔细检查您尝试更改的目录是否输入正确。

I don't have any problem changing InitialDir, either through object inspector or runtime (Win7 with Delphi 2010). Try doublechecking if the directory you try to change to is correctly typed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文