What is the difference between the new TFileOpenDialog and the old TOpenDialog?
In my computer (Win 7/DXE), when I run the code, the dialogs look the same.
TOpenDialog
wraps the traditionalGetOpenFileName
. It works on all versions of Windows.TFileOpenDialog
wraps the new COM based dialog that was introduced in Vista. It therefore only works on Vista or later. It has more functionality than the older dialogs, most notably the tight integration with search.
Vista common dialog
Compatibility common dialog
The GetOpenFileName
API will in fact produce the new dialogs in most situations, if called correctly, so you can't actually tell the difference. That said, historically the VCL's wrapper for GetOpenFileName
was implemented imprecisely and always resulted in the compatibility dialog being shown.
But what does the new COM dialog have to offer then?
The new dialog offers a much easier customisation interface at the loss of some generality. If you use the old dialog template based customisation with GetOpenFileName
on Vista or later then the dialogs degrade to ugly compatibility versions that lack functionality.
The other big advantage of the new dialogs is the ability to select unlimited number of files. The old GetOpenFileName
interface returned multi-select filenames in a fixed size buffer. This can be a real limitation and in my own code I have had to hack the VCL code to make this buffer larger for when my app runs on XP.
TOpenDialog
will delegate the work to TFileOpenDialog
if possible. The test it uses requires all of the following to be true:
- Running on Windows Vista or later.
Dialogs.UseLatestCommonDialogs
global boolean variable is true (default is true). This allows you to disable the use of the new COM dialog should you elect to do so.- No dialog template is specified.
OnIncludeItem
,OnClose
andOnShow
events are all not assigned. Presumably these cannot be fired byTFileOpenDialog
.
Summary
If you continue to use TOpenDialog
then you will reap the benefit of unlimited number of file in multi-select mode. However, if you wish to customise the dialog, and have the new dialogs rather than the ugly compatibilty dialogs, then you need to do the following:
- On XP use
TOpenDialog
and the dialog template method. - On Vista and later use
TFileOpenDialog
and implement customisation withIFileDialogCustomize
.
OpenFilename.Flags := OFN_ENABLEHOOK
in TOpenDialog.DoExecute
. I guess that's needed in order to handle events. So that charge of imprecision is too harsh. –
Choriamb TOpenDialog
executes TFileOpenDialog
when the following conditions are met:
- the program is running under Vista (and up)
UseLatestCommonDialogs
is true (which is the default)- no
OnIncludeItem
,OnClose
orOnShow
events are set
So while still using TOpenDialog
on your system you may likely end up automagically executing TFileOpenDialog
in most cases, which explains why they are looking the same for you.
Remark: TFileOpenDialog
does not fall back on older Windows systems (XP and under) - it just raises an exception. On the opposite, TOpenDialog
does some sort of "fall forward".
TOpenDialog
wraps the traditionalGetOpenFileName
. It works on all versions of Windows.TFileOpenDialog
wraps the new COM based dialog that was introduced in Vista. It therefore only works on Vista or later. It has more functionality than the older dialogs, most notably the tight integration with search.
Vista common dialog
Compatibility common dialog
The GetOpenFileName
API will in fact produce the new dialogs in most situations, if called correctly, so you can't actually tell the difference. That said, historically the VCL's wrapper for GetOpenFileName
was implemented imprecisely and always resulted in the compatibility dialog being shown.
But what does the new COM dialog have to offer then?
The new dialog offers a much easier customisation interface at the loss of some generality. If you use the old dialog template based customisation with GetOpenFileName
on Vista or later then the dialogs degrade to ugly compatibility versions that lack functionality.
The other big advantage of the new dialogs is the ability to select unlimited number of files. The old GetOpenFileName
interface returned multi-select filenames in a fixed size buffer. This can be a real limitation and in my own code I have had to hack the VCL code to make this buffer larger for when my app runs on XP.
TOpenDialog
will delegate the work to TFileOpenDialog
if possible. The test it uses requires all of the following to be true:
- Running on Windows Vista or later.
Dialogs.UseLatestCommonDialogs
global boolean variable is true (default is true). This allows you to disable the use of the new COM dialog should you elect to do so.- No dialog template is specified.
OnIncludeItem
,OnClose
andOnShow
events are all not assigned. Presumably these cannot be fired byTFileOpenDialog
.
Summary
If you continue to use TOpenDialog
then you will reap the benefit of unlimited number of file in multi-select mode. However, if you wish to customise the dialog, and have the new dialogs rather than the ugly compatibilty dialogs, then you need to do the following:
- On XP use
TOpenDialog
and the dialog template method. - On Vista and later use
TFileOpenDialog
and implement customisation withIFileDialogCustomize
.
OpenFilename.Flags := OFN_ENABLEHOOK
in TOpenDialog.DoExecute
. I guess that's needed in order to handle events. So that charge of imprecision is too harsh. –
Choriamb © 2022 - 2024 — McMap. All rights reserved.