I put a TFileSaveDialog
on a form in C++ Builder and set the options fdoOverWritePrompt
, fdoStrictFileTypes
, fdoPathMustExist
, and fdoCreatePrompt
.
When the dialog opens and I select an existing file, it prompts if I want to overwrite like it should. However, if I type in some random name that doesn't exist and click "Save", the dialog just closes - there is no confirmation prompt if it's okay to create one.
Any idea why that is happening?
OFN_CREATEPROMPT
, corresponding toTFileSaveDialog
'sfdoCreatePrompt
orTSaveDialog
'sofCreatePrompt
)is only honored for the Open dialog and never for the Save dialog. Try the same thing with a
TFileOpenDialog
and you get that prompt.Proof for the other dialog types:
Why? Logic wise when saving a file in the majority of cases you want to create a new file (select a non-existing filename) anyway - why is there a need to confirm that again when you already have the "Save" button? Saving a file implies that a file is created. Confirming to overwrite/change an existing file is less common.
If you still want such a behavior you have to do it yourself: use the
OnCanClose
event and then check the filename being chosen/entered so far: