gpt4 book ai didi

delphi - 无法在 InitialDir 中打开 OpenDialog 窗口

转载 作者:行者123 更新时间:2023-12-03 16:38:46 24 4
gpt4 key购买 nike

我在让我的 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:

  1. 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.
  2. Otherwise, if lpstrFile contains a path, that path is the initial directory.
  3. Otherwise, if lpstrInitialDir is not NULL, it specifies the initial directory.
  4. If lpstrInitialDir is NULL and the current directory contains any files of the specified filter types, the initial directory is the current directory.
  5. Otherwise, the initial directory is the personal files directory of the current user.
  6. Otherwise, the initial directory is the Desktop folder.

Windows 2000/XP/Vista:

  1. If lpstrFile contains a path, that path is the initial directory.
  2. Otherwise, lpstrInitialDir specifies the initial directory.
  3. 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.
  4. If lpstrInitialDir is NULL and the current directory contains any files of the specified filter types, the initial directory is the current directory.
  5. Otherwise, the initial directory is the personal files directory of the current user.
  6. Otherwise, the initial directory is the Desktop folder.

您每次都传递相同的值,因此适用规则 1。操作系统会忽略您的程序要求的目录,而是使用用户喜欢的目录。您可能会在旧程序中看到不同的行为,因为您已经随着时间的推移改变了它的行为,并且它不再请求与您第一次运行该程序时相同的初始目录。

您可能不必担心。

关于delphi - 无法在 InitialDir 中打开 OpenDialog 窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26529714/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com