我有一个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
该OP特别要求将初始目录设置为不同的驱动器,您的DFM显示您正在请求'C:\' – 2011-05-06 07:00:42
Hi @Cosmin Prund ....对不起,我不明白..我用'DFM-initialDir'测试了'C:\',但是当'Button1Click'执行时我已经测试过设置'edit1.text '到'D:\ and_folder'和相反。所有运行良好。 – ferpega 2011-05-06 07:05:33
我的意思是,你可以用'OpenDialog1.InitialDir:='D:\ my_folder''来代替'OpenDialog1.InitialDir:= edit1.text;'并且所有工作都正常。我用3个磁盘和不同的文件夹测试了它,因为有一个'edit1'而不是一个常量字符串。 :-) – ferpega 2011-05-06 07:08:15