View Issue Details

IDProjectCategoryView StatusLast Update
0023065LazarusLCLpublic2016-08-21 11:07
ReporterframercyAssigned ToBart Broersma 
Status resolvedResolutionfixed 
Product Version1.0.0Product Build 
Target Version1.6.2Fixed in Version1.6.2 
Summary0023065: TSelectDirectoryDialog: Failure in OnClose and OnShow event handling under WIN32
DescriptionThe OnClose event is triggert on OnShow.

I made up a simple form with an button, editbox and an open file dialog.
The dialog is executed via the button.
On dialog closing the property Filename should be shown in the editbox.

This works under Linux fine for me but not under win32.
Additional InformationI made a small sample Project.

Of interest could be this:

If I assign the SelectDirectoryDialog1Close procedure to the OnShow event in the Objectinspector the things work right...
TagsNo tags attached.
Fixed in Revisionr52801
Attached Files


has duplicate 0023234 resolvedBart Broersma The problem with the event OnClose in the component TSelectDirectoryDialog 
related to 0028636 resolvedBart Broersma TFontDialog - Events not triggered 
related to 0021163 resolvedBart Broersma OnShow is triggered twice in TOpenDialog and TSaveDialog 
child of 0030449 closedBart Broersma TCommonDialog events meta issue 


2012-10-05 19:24 (2,353 bytes)

Bart Broersma

2012-10-06 18:10

developer   ~0062948

Last edited: 2012-10-06 18:34

You obviously meant TSelectDirectoryDialog, not TOpenDialog...
I updated the summary accordingly.

Lazarus 1.1 r38926 FPC 2.6.0 i386-win32-win32/win64

When closing OnShow is called.
None of the other published events are called (OnShow, OnCanClose, OnFolderChange, OnSelectionChange)

OnHelpClicked and onTypeChange do not (seem to) apply to this control on win32.

Bart Broersma

2012-10-06 18:36

developer   ~0062949

As a side note:

"For Windows Vista or later, it is recommended that you use IFileDialog with the FOS_PICKFOLDERS option rather than the SHBrowseForFolder function. This uses the Open Files dialog in pick folders mode and is the preferred implementation."

Since we have the Onxxx events working for TOpenDialog in Vista+ style, this would fix this issue for Vista+ style dialogs...

Bart Broersma

2012-10-13 12:34

developer   ~0063118

See the difference between TOpenDialog and TSelectdirectoryDialog

SelectdirectoryDialog1.Execute calls:
TFileDialog.Execute ->
TCommonDialog.Execute ->
In TWin32WSSelectDirectoryDialog.CreateHandle: call SHBrowseForFolder

--> This will show the SelectDirectoryDialog

Now we return to TCommonDialog.Execute
TCommonDialog.Execute: Handle = 0 (the dialog has already been closed and freed at this stage)

Only now TCommonDialog.DoExecute is called:
TCommonDialog.DoExecute A
TCommonDialog.DoExecute call OnShow (if assigned)
TCommonDialog.DoExecute call WS.ShowModal
TCommonDialog.DoExecute End
TCommonDialog.Execute: Result = True
TCommonDialog.Execute: After Close
TFileDialog.Execute End

OpenDialog1.Execute calls:
TFileDialog.Execute ->
TCommonDialog.Execute ->
TCommonDialog.Execute: Handle = 37670736 ->
TCommonDialog.DoExecute call OnShow (if assigned)
TCommonDialog.DoExecute call WS.ShowModal

--> Dialog is shown

TCommonDialog.DoExecute End
TCommonDialog.Execute: Result = False (I pressed escape)
TCommonDialog.Execute: After Close
TFileDialog.Execute End

Notice that the SelectDirectoryDialog is shown in the call to CreateHandle.
Only after that the common pathaway for TCommonDialog.Execute is called, which then calls OnShow (after the dialog has been closed) and the calls TWSCommonDialogClass(WidgetSetClass).ShowModal(Self), which is supposed to show the dialog (I guess).
For TWin32WSSelectDirectoryDialog ShowModal is not overridden and calls the empty implementation TWSCommonDialog.ShowModal.
In TCommonDialog.Execute Close is called, but since at this point Handle = 0, HandleAllocated = false and DoClose (which invokes Onclose) will never be called.

The way TCommonDialog is constructed means (I think) that is descendants must only actually show the dialog via the TWSCommonDialogClass(WidgetSetClass).ShowModal(Self)method, or else the Onxxx events will not be fired, or fired at the wrong moment.

Bart Broersma

2016-08-13 20:06

developer   ~0094113

Please test and close if OK.

Issue History

Date Modified Username Field Change
2012-10-05 19:24 framercy New Issue
2012-10-05 19:24 framercy File Added:
2012-10-05 19:24 framercy Widgetset => Win32/Win64
2012-10-06 18:10 Bart Broersma LazTarget => -
2012-10-06 18:10 Bart Broersma Note Added: 0062948
2012-10-06 18:10 Bart Broersma Status new => confirmed
2012-10-06 18:32 Bart Broersma Note Edited: 0062948
2012-10-06 18:33 Bart Broersma Summary TOpenFileDialog: Failure in OnClose and OnShow event handling under WIN32 => TSelectDirectoryDialog: Failure in OnClose and OnShow event handling under WIN32
2012-10-06 18:34 Bart Broersma Note Edited: 0062948
2012-10-06 18:36 Bart Broersma Note Added: 0062949
2012-10-13 12:34 Bart Broersma Note Added: 0063118
2012-10-28 22:15 Bart Broersma Relationship added has duplicate 0023234
2015-09-09 11:34 Bart Broersma Relationship added related to 0028636
2016-08-08 00:12 Bart Broersma Relationship added related to 0021163
2016-08-08 12:41 Bart Broersma Relationship added child of 0030449
2016-08-13 20:06 Bart Broersma Fixed in Revision => r52801
2016-08-13 20:06 Bart Broersma LazTarget - => 1.6.2
2016-08-13 20:06 Bart Broersma Note Added: 0094113
2016-08-13 20:06 Bart Broersma Status confirmed => resolved
2016-08-13 20:06 Bart Broersma Fixed in Version => 1.6.2
2016-08-13 20:06 Bart Broersma Resolution open => fixed
2016-08-13 20:06 Bart Broersma Assigned To => Bart Broersma
2016-08-13 20:06 Bart Broersma Target Version => 1.6.2