简体   繁体   English

在 Delphi 10.1 Berlin 中使用 VCL 样式时,TSaveDialog 的属性“ofOverwritePrompt”不起作用

[英]Property "ofOverwritePrompt" for TSaveDialog does not work when VCL Styles are used in Delphi 10.1 Berlin

  1. Create a new VCL Forms application创建一个新的 VCL Forms 应用程序
  2. On the main form add a Tbutton and a TSaveDialog在主窗体上添加一个 Tbutton 和一个 TSaveDialog

  3. Set "ofOverwritePrompt" to True in properties for the SaveDialog1在 SaveDialog1 的属性中将“ofOverwritePrompt”设置为 True

  4. Use:用:

     procedure TForm1.Button1Click(Sender: TObject); begin SaveDialog1.Execute(); end;
  5. Run the app.运行应用程序。 Press the button to execute the save dialog.按 按钮执行保存对话框。 Try to save to a file that already exists.尝试保存到一个已经存在的文件。 A message box appears if you want to replace the file.如果您想替换该文件,则会出现一个消息框。 Press cancel.按取消。 All fine so far.到目前为止一切都很好。 Close the app.关闭应用程序。

  6. Go to Project/Options/Application/Appearance and select a Custom style (eg Amakrits).转到项目/选项/应用程序/外观并选择自定义样式(例如 Amakrits)。 Set Amakrits as the default style.将 Amakrits 设置为默认样式。

  7. Run the app as in #5 above.按照上面的#5 运行应用程序。 Only a small bit of the message box will be shown.只会显示消息框的一小部分。 You will have to press Enter to be able to continue.您必须按 Enter 才能继续。

(Using a TFileSaveDialog will give the same result) (使用 TFileSaveDialog 将给出相同的结果)

If I compile and run the app using Delphi XE8 it will be ok since the save dialog window seems to use the default windows style even if another style is chosen.如果我使用 Delphi XE8 编译并运行该应用程序,它会没问题,因为即使选择了另一种样式,保存对话框窗口似乎也使用默认的窗口样式。

Edit: I have Windows 10 pro.编辑:我有 Windows 10 专业版。 Source compiled as win32 with Delphi 10.1 Berlin.使用 Delphi 10.1 Berlin 编译为 win32 的源代码。 The replace message box is partly hidden.替换消息框部分隐藏。 Only a small top left part is shown, see figure.只显示了左上角的一小部分,见图。

替换消息框部分隐藏。只显示了一个小的左上角部分。

And here it is compiled with XE8 win32:这里是用 XE8 win32 编译的:

在此处输入图片说明

Ps.附言。 I am using the default 100% scale factor.我使用默认的 100% 比例因子。

Compiling with win64 (Delphi 10.1 Berlin) seems to be ok:用 win64 (Delphi 10.1 Berlin) 编译似乎没问题:

在此处输入图片说明

So, compiling to win32 does not work for me, but 64-bit will.因此,编译到 win32 对我不起作用,但 64 位可以。 Any clues?有什么线索吗?

Edit: Trying with "GetSaveFileName(OFN)" will also not work for me in win32 (win 64 is ok):编辑:在 win32 中尝试使用“GetSaveFileName(OFN)”也对我不起作用(win 64 可以):

在此处输入图片说明

You can avoid this issue using the dialog styling code of the VCL Styles Utils project.您可以使用VCL Styles Utils项目的对话框样式代码来避免此问题。

Just Add these units to your project.只需将这些单位添加到您的项目中。

uses
  Vcl.Styles.Utils.Menus, //Popup and Shell Menus (class #32768)
  Vcl.Styles.Utils.Forms, //dialogs box (class #32770)
  Vcl.Styles.Utils.StdCtrls, //buttons, static, and so on
  Vcl.Styles.Utils.ComCtrls, //SysTreeView32, SysListView32
  Vcl.Styles.Utils.ScreenTips, //tooltips_class32 class
  Vcl.Styles.Utils.SysControls,
  Vcl.Styles.Utils.SysStyleHook;

{$R *.dfm}

procedure TForm26.Button1Click(Sender: TObject);
begin
  UseLatestCommonDialogs := false;
  SaveDialog1.Execute();
end;

在此处输入图片说明

I cannot confirm the problem, and all looks well here, (32 bit executalbe, themed with Amakrits, compiled with 10.1 Berlin, on Windows 7, 100% scaling) but you could try this:我无法确认这个问题,这里一切看起来都很好,(32 位可执行文件,以 Amakrits 为主题,使用 10.1 Berlin 编译,在 Windows 7 上,100% 缩放)但你可以试试这个:

uses ... Winapi.CommDlg;

...

var
  OFN: TOpenFileName;
begin
  FillChar(OFN, SizeOf(OFN), 0);
  OFN.lStructSize := SizeOf(OFN);
  OFN.nMaxFile := MAX_PATH;
  OFN.Flags := OFN_OVERWRITEPROMPT or OFN_HIDEREADONLY or OFN_ENABLESIZING or OFN_EXPLORER;
  GetSaveFileName(OFN);
end;

The result is an Amakrits-themed, new Explorer-like save dialog, which works fine (for me).结果是一个以 Amakrits 为主题的、新的类似资源管理器的保存对话框,效果很好(对我来说)。 Only the two round, blue "back" and "forth" ( <- and -> ) buttons at the top left of the dialog look a little weird.只有对话框左上角的两个圆形蓝色“后退”和“前进”( <--> )按钮看起来有点奇怪。

But I did not try this with custom scaling settings (eg Medium 125% in the Control Panel -> Display panel, etc.).但我没有尝试使用自定义缩放设置(例如,控制面板 -> 显示面板中的中等 125%,等等)。 I think this could influence such things.我认为这可能会影响这些事情。

Update更新

I just tried to use SaveDialog1 (commenting out the OFN code above) with custom Display scaling (125%).我只是尝试使用具有自定义显示缩放比例 (125%) 的SaveDialog1 (注释掉上面的 OFN 代码)。 All looked fine, so that is not it.一切看起来都很好,所以不是这样。 Also when I use the OFN code, all looks fine (actually, better, ie no XP style dialog, but a real Explorer-like dialog instead).此外,当我使用 OFN 代码时,一切看起来都很好(实际上更好,即没有 XP 风格的对话框,而是一个真正的类似资源管理器的对话框)。

If I set "Enable High-DPI" to true in Project/Options/Application it will work (replace box properly displayed).如果我在项目/选项/应用程序中将“启用高 DPI”设置为 true,它将起作用(替换正确显示的框)。 Disabling it will cause the problem (both in win32 and win64).禁用它会导致问题(在 win32 和 win64 中)。

For the record, I had exactly the same problem (Delphi 10.1 Berlin, compiling on Windows 10 64 bit, 100% screen settings, compiled for 32 bit target).作为记录,我遇到了完全相同的问题(Delphi 10.1 Berlin,在 Windows 10 64 位上编译,100% 屏幕设置,为 32 位目标编译)。 Enabling or disabling High-DPMI awareness didn't help.启用或禁用高 DPMI 意识没有帮助。

A workaround is to disable styles for dialog boxes before executing the TSaveDialog (or TOpenDialog) like this:一种解决方法是在执行 TSaveDialog(或 TOpenDialog)之前禁用对话框的样式,如下所示:

  TStyleManager.SystemHooks := TStyleManager.SystemHooks - [shDialogs];

The file dialog itself will still be themed.文件对话框本身仍将是主题。 You will get standard Windows-style message boxes in case an overwrite prompt (or create prompt) pops up, but they will be large enough for the user to read and click them.如果出现覆盖提示(或创建提示),您将获得标准的 Windows 风格的消息框,但它们足够大,用户可以阅读和单击它们。 After the file dialog has finished, you can enable styled dialogs again by re-adding shDialogs to SystemHooks if needed.文件对话框完成后,如果需要,您可以通过将 shDialogs 重新添加到 SystemHooks 来再次启用样式对话框。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM