lcl: better bullet-proof LCL approach for r51808 #cf74370262, issue #28631

git-svn-id: trunk@51810 -
This commit is contained in:
ondrej 2016-03-03 07:45:45 +00:00
parent 385957f10b
commit 2425ad6bff

View File

@ -28,9 +28,7 @@ function TCommonDialog.Execute: boolean;
var var
DisabledList: TList; DisabledList: TList;
SavedFocusState: TFocusState; SavedFocusState: TFocusState;
FocusedWindow: HWnd;
begin begin
FocusedWindow := GetFocus;
SavedFocusState := SaveFocusState; SavedFocusState := SaveFocusState;
DisabledList := Screen.DisableForms(Screen.ActiveForm); DisabledList := Screen.DisableForms(Screen.ActiveForm);
try try
@ -41,8 +39,9 @@ begin
finally finally
Screen.EnableForms(DisabledList); Screen.EnableForms(DisabledList);
RestoreFocusState(SavedFocusState); RestoreFocusState(SavedFocusState);
if IsWindow(FocusedWindow) and (GetFocus<>FocusedWindow) then if (Screen.ActiveControl<>nil) and (Screen.ActiveControl.HandleAllocated)
SetFocus(FocusedWindow); and (GetFocus<>Screen.ActiveControl.Handle) then
SetFocus(Screen.ActiveControl.Handle); // must restore focus after Screen.EnableForms
end; end;
end; end;