From 47bd1163f879721aa3d113e9862c7609fc62fa55 Mon Sep 17 00:00:00 2001 From: paul Date: Tue, 11 May 2010 00:43:11 +0000 Subject: [PATCH] lcl: calling of CM_EXIT can cause other focus changes in the user code, so we need to change FLastFocusedControl before the call (based on demo of Zeljan) git-svn-id: trunk@25309 - --- lcl/include/customform.inc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lcl/include/customform.inc b/lcl/include/customform.inc index 93fc871e1e..8a1000cd85 100644 --- a/lcl/include/customform.inc +++ b/lcl/include/customform.inc @@ -2138,6 +2138,7 @@ function TCustomForm.SetFocusedControl(Control: TWinControl): Boolean; var LastState: TFocusState; + Tmp: TWinControl; begin // send cm_exit, cm_enter messages // cm_exit must be sent to all controls from lastfocusedcontrol to the first parent which contains control @@ -2147,10 +2148,13 @@ function TCustomForm.SetFocusedControl(Control: TWinControl): Boolean; while not FLastFocusedControl.ContainsControl(Control) do begin LastState := SaveFocusState; - FLastFocusedControl.Perform(CM_EXIT, 0, 0); + // calling of CM_EXIT can cause other focus changes - so FLastFocusedControl can change after the call + // therefore we need to change it before the call + Tmp := FLastFocusedControl; + FLastFocusedControl := Tmp.Parent; + Tmp.Perform(CM_EXIT, 0, 0); if SaveFocusState <> LastState then Exit(False); - FLastFocusedControl := FLastFocusedControl.Parent; end; while FLastFocusedControl <> Control do