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,
TOpenDialog
is a wrapper for theGetOpenFileName()
API, whereTOpenDialog.InitialDir
maps to theOPENFILENAME.lpstrInitialDir
field.On Vista and later,
TOpenDialog
(usually, depending on configuration) wraps theIFileDialog
/IFileOpenDialog
API instead, whereTOpenDialog.InitialDir
maps to theIFileDialog.SetFolder()
method (not toIFolderDialog.SetDefaultFolder()
, as one would expect).Per the
OPENFILENAME
documentation:And per the Common Item Dialog documentation:
Neither
TOpenDialog
norTFileOpenDialog
have properties that map to theIFileDialog.SetDefaultFolder()
orIFileDialog.SetSaveAsItem()
methods. However, theTFileOpenDialog.Dialog
property does give you access to the underlyingIFileDialog
, so you can manually call these methods, such as in theTFileOpenDialog.OnExecute
event.