Property "ofOverwritePrompt" for TSaveDialog does not work when VCL Styles are used in Delphi 10.1 Berlin
Asked Answered
W

4

8
  1. Create a new VCL Forms application
  2. On the main form add a Tbutton and a TSaveDialog

  3. Set "ofOverwritePrompt" to True in properties for the SaveDialog1

  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 (e.g. Amakrits). Set Amakrits as the default style.

  7. Run the app as in #5 above. Only a small bit of the message box will be shown. You will have to press Enter to be able to continue.

(Using a TFileSaveDialog will give the same result)

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.

Edit: I have Windows 10 pro. Source compiled as win32 with Delphi 10.1 Berlin. The replace message box is partly hidden. Only a small top left part is shown, see figure.

The replace message box is partly hidden. Only a small top left part is shown.

And here it is compiled with XE8 win32:

enter image description here

Ps. I am using the default 100% scale factor.

Compiling with win64 (Delphi 10.1 Berlin) seems to be ok:

enter image description here

So, compiling to win32 does not work for me, but 64-bit will. Any clues?

Edit: Trying with "GetSaveFileName(OFN)" will also not work for me in win32 (win 64 is ok):

enter image description here

Wriggle answered 20/7, 2016 at 15:43 Comment(13)
Sorry, can't reproduce it. Windows 7 Ultimate 64 bit, but compiled with Berlin as 32 bit target. Could you edit your question to show the Windows version? Anyway, my messagebox shows fine. Are you using a scaling factor, e.g. 120% or 150% in your Windows settings? Here, the SaveDialog as well as the messagebox use Amakrits, and all looks fine.Terefah
FWIW, the SaveDialog looks like an XP dialog box, not the Explorer style you usually see in Win7+. But the question is good, +1.Terefah
I cannot recreate this either, using Delphi 10 Seattle under Windows 10 Pro 64bit. Can you show us a screenshot of what you're talking about?Lyckman
@JerryDodge: if themed, does your Save Dailog look like an XP one recently visited places on the left) or like a Windows 7/8/8.1/10 one, e.g. more or less like a slightly smaller explorer (treeview on the left, listview on the right, etc.)?Terefah
@Rudy Interesting, without the theme, it shows the newer dialog style (tree view), but with a theme, it shows the old XP one (Quick Access, Desktop, Libraries, This PC, and Network buttons).Lyckman
@JerryDodge: same here. I guess the current save dialog was not so easy to theme. <g>Terefah
I can't reproduce the issue which you describe, Can you please attach a sample image? Also the original code to style the system dialogs is part of the VCL Styles Utils project. Starting with RAD Studio Seattle EMB acquire a small part of the code to styling the dialogs, so only the classic open/save dialogs are supported by the Embarcadero VCL Styles version. If you want full support for the New Dialogs try the VCL Styles Utils project.Joab
@JerryDodge: If I use GetSaveFileName() with the appropriate settings, I see a themed Explorer-style dialog, but the two round buttons at the top left (back, forward) are not styled properly. I guess that is why they decided to use the old XP style.Terefah
FWIW, I tried this on Win10 too, and it works as expected. I don't see a mutilated message box like in the picture. Here, it looks fine.Terefah
Oh! I saw this actually, now that you show a screenshot. This happened randomly in a save dialog in our own software about a month ago. After rebooting Windows, it started showing fine again.Lyckman
@Rudy: Thanks Rudy. I just want to make sure that you use win32?I get the error every time even if Windows 10 is rebooted. Could we exchange exe-files to see if there will be a difference on each others PC? Does anyone know if I can disable the style theme for the save dialog only (as it appears in the case of using XE8)?Wriggle
I used Win32 and Win64. No differences. Did you try my GetSaveFileName example? How does that do for you?Terefah
Trying with "GetSaveFileName(OFN)" will also not work for me in win32 (win 64 is ok), see picture #4 above.Wriggle
J
4

You can avoid this issue using the dialog styling code of the VCL Styles Utils project.

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;

enter image description here

Joab answered 23/7, 2016 at 6:49 Comment(1)
This will also work for me. Thanks for a great job with "VCL Styles Utils".Wriggle
T
2

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:

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). 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 (e.g. Medium 125% in the Control Panel -> Display panel, etc.). 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%). All looked fine, so that is not it. Also when I use the OFN code, all looks fine (actually, better, i.e. no XP style dialog, but a real Explorer-like dialog instead).

Terefah answered 20/7, 2016 at 17:26 Comment(0)
W
1

If I set "Enable High-DPI" to true in Project/Options/Application it will work (replace box properly displayed). Disabling it will cause the problem (both in win32 and win64).

Wriggle answered 22/7, 2016 at 6:58 Comment(0)
J
1

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). Enabling or disabling High-DPMI awareness didn't help.

A workaround is to disable styles for dialog boxes before executing the TSaveDialog (or TOpenDialog) like this:

  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. After the file dialog has finished, you can enable styled dialogs again by re-adding shDialogs to SystemHooks if needed.

Judyjudye answered 10/7, 2018 at 16:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.