How Win11 decides the default File Save As Location with TSaveDialog that has ofNoChangeDir flag (Win32 Delphi App)

129 Views Asked by At

There is a problem when saving the PDF file, the default "last used folder" may be sometimes set by OS to a folder that does not respond and this causes my app to hang when opening SaveAs Dialog with Win32 api.

Now one client has an issue that the remembered default folder is causing a weird hanging. I need to reset this default last used path somehow, without changing the code block (see below).

How is the OS choosing and remembering this default path? It seems OS remembers my previous folder selection when EXE is started again. My win32 app is using chdir() to change the default path to the location of exe inside "program files x86", but the OS does not seem to give that folder as a default location to SaveAs dialog. Also, the Icon/Shortcut has the Start in folder setting, but its not used either.

My app does not itself store the default path changed by end-user, but still when I come back to save PDF file next time, the app somehow remembers the exactly same path, that was used earlier.

FileOpenDialog := TSaveDialog.create(parent);
FileOpenDialog.DefaultExt := '*.pdf';
FileOpenDialog.filename := 'Report';
FileOpenDialog.Filter := 'PDF Document (*.pdf)|*.pdf|Bitmap image (*.bmp)|*.bmp';
FileOpenDialog.options := [ofNoChangeDir,ofPathMustExist,ofHideReadOnly,ofNoReadOnlyReturn ,ofOverwritePrompt   ];
FileOpenDialog.title := 'Save PDF';
if not FileOpenDialog.Execute then exit;

I have searched the whole Registry but cannot find where OS is saving the "last used folder".

0

There are 0 best solutions below