I am using TOpenDialog (in Delphi 10.4) to show the user the PDF files I have installed for them in their Documents folder. In that folder, I have created a folder MyFolder10.2 and copied the PDF files there.
The code is simple and has worked in the past, and even now it still works on my older slower Win10 machine. But on my newer faster Win10 computer, it only works SOME of the time. When it does not work, a file dialog is opened but in some other directory (not sure where that comes from), and it does not filter the file type (.pdf) that was set in the TOpenDialog component.
Any way to track down this mystery?
docPath:= GetEnvironmentVariable('USERPROFILE') + '\Documents\MyFolder10.2\';
OpenDocsDlg.InitialDir := docPath;
OpenDocsDlg.Execute;
Prior to Vista,
TOpenDialogis a wrapper for theGetOpenFileName()API, whereTOpenDialog.InitialDirmaps to theOPENFILENAME.lpstrInitialDirfield.On Vista and later,
TOpenDialog(usually, depending on configuration) wraps theIFileDialog/IFileOpenDialogAPI instead, whereTOpenDialog.InitialDirmaps to theIFileDialog.SetFolder()method (not toIFolderDialog.SetDefaultFolder(), as one would expect).Per the
OPENFILENAMEdocumentation:And per the Common Item Dialog documentation:
Neither
TOpenDialognorTFileOpenDialoghave properties that map to theIFileDialog.SetDefaultFolder()orIFileDialog.SetSaveAsItem()methods. However, theTFileOpenDialog.Dialogproperty does give you access to the underlyingIFileDialog, so you can manually call these methods, such as in theTFileOpenDialog.OnExecuteevent.