- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在让我的 OpenDialog 窗口在指定的 initialdir 中启动时遇到问题。我目前拥有的是tihs
procedure TForm1.fileMenuLoadClick(Sender: TObject);
begin
SetCurrentDir(StartDir);
SetCurrentDir('Cases');
OpenDialog.Filename := '';
OpenDialog.InitialDir := GetCurrentDir;
OpenDialog.Filter := 'Sparfiler (.dat)|*.dat';
// -------------------------------
if OpenDialog.Execute then
begin
GeometryClear;
DerobModel.Filename := OpenDialog.Filename;
DerobModel.Open;
pressed := True;
SetCurrentDir('../');
DerobModel.HouseProperties.StringValue['CaseDir'] := GetCurrentDir;
DerobModel.HouseProperties.StringValue['StartDir'] := StartDir;
SetCurrentDir(StartDir);
UpdateGeometryPanel;
mainUpdateComboBox;
UpdatePropertiesPanel;
UpdateEnergyPanel;
UpdateAbsorption;
UpdateClimatePanel;
UpdateClimate;
mainHide;
Geometry.IsSelected := True;
GeometryPanel.Visible := True;
TreeView1.Enabled := True;
TreeView1.HitTest := True;
DerobModel.HouseProperties.BoolValue['GlazeChange'] := False;
end;
运行此代码时,它会不断打开我上次打开的文件所在的文件夹。我读到解决方案是清除 OpenDialog 的 FileName 属性,但它不起作用。然而有趣的是,它正在使用来 self 的应用程序以前版本的代码。
procedure TForm1.fileMenuLoadClick(Sender: TObject);
begin
SetCurrentDir(StartDir);
SetCurrentDir('Cases');
OpenDialog.Filename := '';
OpenDialog.InitialDir := GetCurrentDir;
OpenDialog.Filter := 'Sparfiler (.dat)|*.dat';
// -------------------------------
if OpenDialog.Execute then
begin
GeometryClear;
DerobModel.Filename := OpenDialog.Filename;
DerobModel.Open;
pressed := True;
SetCurrentDir('../');
DerobModel.HouseProperties.StringValue['CaseDir'] := GetCurrentDir;
DerobModel.HouseProperties.StringValue['StartDir'] := StartDir;
SetCurrentDir(StartDir);
UpdateGeometryPanel;
mainUpdateComboBox;
LoadClimateFiles;
UpdatePropertiesPanel;
UpdateEnergyPanel;
UpdateAbsorption;
UpdateClimatePanel;
UpdateClimate;
mainHide;
Geometry.IsSelected := True;
GeometryPanel.Visible := True;
TreeView1.Enabled := True;
TreeView1.HitTest := True;
DerobModel.HouseProperties.BoolValue['GlazeChange'] := False;
end;
end;
任何人都可以帮我解决这让我发疯的问题。我的意思是唯一的区别是函数 LoadClimateFiles 但现在是在其他函数之一中调用的。调试器说 InitialDir 是我想要的位置并且 FileName 属性是 ''
最佳答案
这种行为是正常的。请参阅 OpenFileName.lpstrInitialDir
的文档领域:
The initial directory. The algorithm for selecting the initial directory varies on different platforms.
Windows 7:
- If
lpstrInitialDir
has the same value as was passed the first time the application used an Open or Save As dialog box, the path most recently selected by the user is used as the initial directory.- Otherwise, if
lpstrFile
contains a path, that path is the initial directory.- Otherwise, if
lpstrInitialDir
is notNULL
, it specifies the initial directory.- If
lpstrInitialDir
isNULL
and the current directory contains any files of the specified filter types, the initial directory is the current directory.- Otherwise, the initial directory is the personal files directory of the current user.
- Otherwise, the initial directory is the Desktop folder.
Windows 2000/XP/Vista:
- If
lpstrFile
contains a path, that path is the initial directory.- Otherwise,
lpstrInitialDir
specifies the initial directory.- Otherwise, if the application has used an Open or Save As dialog box in the past, the path most recently used is selected as the initial directory. However, if an application is not run for a long time, its saved selected path is discarded.
- If
lpstrInitialDir
isNULL
and the current directory contains any files of the specified filter types, the initial directory is the current directory.- Otherwise, the initial directory is the personal files directory of the current user.
- Otherwise, the initial directory is the Desktop folder.
您每次都传递相同的值,因此适用规则 1。操作系统会忽略您的程序要求的目录,而是使用用户喜欢的目录。您可能会在旧程序中看到不同的行为,因为您已经随着时间的推移改变了它的行为,并且它不再请求与您第一次运行该程序时相同的初始目录。
您可能不必担心。
关于delphi - 无法在 InitialDir 中打开 OpenDialog 窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26529714/
我在让我的 OpenDialog 窗口在指定的 initialdir 中启动时遇到问题。我目前拥有的是tihs procedure TForm1.fileMenuLoadClick(Sender: T
我正在使用 GetOpenFileName并设置 lpstrInitialDir OPENFILENAME成员(member)struct 到我想要的目录作为初始目录。但是在 Win7 上,我的应用程
我是一名优秀的程序员,十分优秀!