I have an old application, untouched for a long time, built with C++ Builder 2009, that still works fine.
That is to say ..
Today I noticed some of the TSaveDialog->Options don't work as intended on my Windows 10 system. To make sure I'm not dreaming I tested the same application on an older Windows version (I tried XP) and there it worked perfectly fine as intended.
The TSaveDialog instance is setup at design time with Options: [ofHideReadOnly,ofAllowMultiSelect,ofEnableSizing]
I noticed today (on Windows 10) that ofAllowMultiSelect doesn't work anymore ?
Instead ofOverwritePrompt is (incorrectly) used !
In other words I cannot select two ore more files anymore and when I select a file that already exists I first get a 'Confirm Save As' dialog.
When I compile again on my Windows 10 system, using C++ Builder 2009, in debug mode and inspect Options, the debugger seems to (still) properly see ofHideReadOnly, ofAllowMultiSelect, ofEnableSizing, yet the problem persists. So it's not as if the values changed somehow ?
When I try at runtime:
SaveDialog->Options.Clear() ;
SaveDialog->Options << ofHideReadOnly << ofEnableSizing << ofAllowMultiSelect ;
the problem also persists !
When I remove ofAllowMultiSelect (at run time or at design time) 'Confirm Save As' is not shown anymore on an existing file (but I obviously also still can't select multiple files).
I'm flabbergasted by this to be honest ? Not sure what to do next ? I have no option to test a more recent c++ version but I'm also having difficulties comprehending how the compiler could be responsible here.
Any guidance appreciated.
Delphi tag added because of VCL overlap between c++ Builder and Delphi
On Windows Vista and later, IF AND ONLY IF all of these conditions are met:
Dialogs::UseLatestCommonDialogsvariable istrueTSaveDialog::Templateproperty isNULLTSaveDialog::OnIncludeItem,TSaveDialog::OnClose, andTSaveDialog::OnShowevents have no handlers assignedThen
TSaveDialogwill internally use the Win32IFileSaveDialoginterface, where theofAllowMultiSelectoption will be mapped to that dialog'sFOS_ALLOWMULTISELECToption, which is NOT SUPPORTED byIFileSaveDialog, only byIFileOpenDialog, per the documentation:If the above 3 conditions are not satisfied, then
TSaveDialogwill internally use the Win32GetSaveFileName()function instead, where theofAllowMultiSelectoption will be mapped to that dialog'sOFN_ALLOWMULTISELECToption, which IS SUPPORTED byGetSaveFileName()1.That is why you are seeing behavioral differences when running your app on Windows XP vs Windows 10.
So, if you want the old
TSaveDialogbehavior on newer Windows versions, you need to make sure at least 1 of those 3 conditions is not satisfied. For instance, by settingUseLatestCommonDialogs=falsebefore callingSaveDialog->Execute(), or by assigning an (empty) event handler to one of theOnIncludeItem/OnClose/OnShowevents.Or, you could simply call
GetSaveFileName()directly, instead of usingTSaveDialogat all.1: However, just note that on Vista+,
GetSaveFileName()is just a wrapper forIFileSaveDialog, and is provided only for backwards compatibility. So, you still might not get the exact behavior you want even if you did useGetSaveFileName()on Windows 10.On a side note: this code does not work the way you think it does:
The
Optionsproperty is not actually updated! In both statements, theOptionsproperty is read from, returning a temporaryTOpenOptions, which you are then modifying, but not assigning back to theOptionsproperty. IOW, the code is effectively doing the following:So, to update the
Optionsproperty correctly, use this instead: