Delphi2010中的GetDir在Windows 7下不起作用?

发布于 2024-09-25 02:03:25 字数 371 浏览 10 评论 0原文

我在 Delphi2010 中有以下命令序列:

  var netdir:string;
  ....
  OpenDialog1.InitialDir:=netdir;
  ....
  OpenDialog1.Execute...
  ....
  GetDir(0,netdir);
  ....

执行 OpenDialog 后,我应该在字符串 netdir 中包含我完成的目录 我的 OpenDialog.Execute。在下一个 OpenDialog.Execute 中应该从那里开始 目录。 在 XP 上运行正常,但在 Windows 7 上就不行? 它始终从程序安装的目录开始。

知道可能出了什么问题吗?

谢谢。

I have the following sequence of commands in Delphi2010:

  var netdir:string;
  ....
  OpenDialog1.InitialDir:=netdir;
  ....
  OpenDialog1.Execute...
  ....
  GetDir(0,netdir);
  ....

After executing OpenDialog I should have in string netdir the directory where I finished
my OpenDialog.Execute. And in the next OpenDialog.Execute it should start from that
directory.
It works fine on XP, but not on Windows 7?
It always starts from directory where the program is installed.

Any idea what might be wrong?

Thanks.

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

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

发布评论

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

评论(3

爱你是孤单的心事 2024-10-02 02:03:25

您的问题无法按目前的情况得到回答,因为它缺少几个关键细节。

  1. netdir 是全局常量,还是时常超出范围?
  2. 您是否将 netdir 设置为 OpenDialog1.Execute 之前的内容?
  3. 问题是关于 GetDir 返回什么目录(如标题所示),还是如何使打开的对话框记住上次访问的目录(如正文所示)?

我假设 1) netdir 是一个全局常量,2) 您最初没有设置它,3) 您希望打开的对话框记住上次访问的文件夹。因此你有类似的东西

unit Unit3;

interface

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

type
  TForm3 = class(TForm)
    OpenDialog1: TOpenDialog;
    procedure FormClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form3: TForm3;

var
  netdir: string;

implementation

{$R *.dfm}

procedure TForm3.FormClick(Sender: TObject);
begin
  OpenDialog1.InitialDir := netdir;
  OpenDialog1.Execute;
  GetDir(0, netdir);
end;

end.

那么解决方案是让Windows为你记住目录,即简单地

procedure TForm3.FormClick(Sender: TObject);
begin
  OpenDialog1.Execute;
end;

单独做!但为什么你的方法不起作用呢?好吧,GetDir 不会返回您想要的内容。如果您需要显式控制,请执行

procedure TForm3.FormClick(Sender: TObject);
begin
  OpenDialog1.InitialDir := netdir;
  OpenDialog1.Execute;
  netdir := ExtractFilePath(OpenDialog1.FileName)
end;

Your question cannot be answered as it stands, because it lacks several crucial details.

  1. Is netdir a global constant, or does it go out of scope every now and then?
  2. Do you set netdir to something prior to OpenDialog1.Execute?
  3. Is the question about what directory GetDir return (as your title suggests), or about how to make the open dialog remember the last visited directory (as the body matter suggests)?

I will assume that 1) netdir is a global constant, that 2) you do not set it initially, and that 3) you want the open dialog to remember the last visited folder. Thus you have something like

unit Unit3;

interface

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

type
  TForm3 = class(TForm)
    OpenDialog1: TOpenDialog;
    procedure FormClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form3: TForm3;

var
  netdir: string;

implementation

{$R *.dfm}

procedure TForm3.FormClick(Sender: TObject);
begin
  OpenDialog1.InitialDir := netdir;
  OpenDialog1.Execute;
  GetDir(0, netdir);
end;

end.

Then the solution is to let Windows remember the directory for you, that is, simply do

procedure TForm3.FormClick(Sender: TObject);
begin
  OpenDialog1.Execute;
end;

alone! But why doesn't your method work? Well, GetDir doesn't return what you want. If you need explicit control, do

procedure TForm3.FormClick(Sender: TObject);
begin
  OpenDialog1.InitialDir := netdir;
  OpenDialog1.Execute;
  netdir := ExtractFilePath(OpenDialog1.FileName)
end;
羁〃客ぐ 2024-10-02 02:03:25

如果您不想打开对话框,您可以执行以下操作以获取程序下的目录。

yourdir:=ExtractFilePath(Application.ExeName);

我已经在 Vista 中完成了,并且有效。

If you not wan´t opendialog you can do as below to get dir under your program.

yourdir:=ExtractFilePath(Application.ExeName);

I have done it in Vista and it work.

感悟人生的甜 2024-10-02 02:03:25

这是问题的解决方案

openDialog1.Options := [ofFileMustExist];

if openDialog1.Execute then
begin

end;

This is the solution for the problem

openDialog1.Options := [ofFileMustExist];

if openDialog1.Execute then
begin

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