From c5637ad72a132714f3e6452052ebfbeecf66fcd6 Mon Sep 17 00:00:00 2001 From: bart <9132501-flyingsheep@users.noreply.gitlab.com> Date: Wed, 25 Oct 2017 09:26:50 +0000 Subject: [PATCH] Fix firing an OnChange and setting Modified when setting Text inside OnChange and new Text = old Text. Issue #0032602. git-svn-id: trunk@56181 - --- lcl/include/customedit.inc | 9 +++++---- lcl/include/wincontrol.inc | 6 +++++- lcl/stdctrls.pp | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lcl/include/customedit.inc b/lcl/include/customedit.inc index 35bdc9be0c..5332178386 100644 --- a/lcl/include/customedit.inc +++ b/lcl/include/customedit.inc @@ -81,7 +81,7 @@ begin BorderStyle := bsSingle; FAutoSelect := True; FAutoSelected := False; - FTextChangedByRealSetText := False; + FTextChangedByRealSetTextCounter := 0; AutoSize := True; // Accessibility AccessibleRole := larTextEditorSingleline; @@ -548,10 +548,11 @@ begin if (FEmulatedTextHintStatus=thsShowing) and (AValue<>'') then HideEmulatedTextHint; - FTextChangedByRealSetText := True; + Inc(FTextChangedByRealSetTextCounter); Modified := False; inherited RealSetText(AValue); - FTextChangedByRealSetText := False; + Dec(FTextChangedByRealSetTextCounter); + if (FTextChangedByRealSetTextCounter < 0) then FTextChangedByRealSetTextCounter := 0; if (FEmulatedTextHintStatus=thsHidden) and CanShowEmulatedTextHint then ShowEmulatedTextHint; @@ -601,7 +602,7 @@ begin begin if ([csLoading,csDestroying]*ComponentState=[]) then begin - if not FTextChangedByRealSetText then + if (FTextChangedByRealSetTextCounter = 0) then Modified := True; Change; end; diff --git a/lcl/include/wincontrol.inc b/lcl/include/wincontrol.inc index 8beaa9841d..f88d7b7c26 100644 --- a/lcl/include/wincontrol.inc +++ b/lcl/include/wincontrol.inc @@ -8297,7 +8297,11 @@ begin begin WSSetText(AValue); InvalidatePreferredSize; - inherited RealSetText(AValue); + //don't call inherited (=TControl.)RealSetText(AValue) since it can issue a + //second OnChange if RealSetText is called from within OnChange (#0032602) + //instead just update FCaption. + //WSSetText already makes sure an OnChange will be performed + FCaption := AValue; AdjustSize; end else inherited RealSetText(AValue); diff --git a/lcl/stdctrls.pp b/lcl/stdctrls.pp index 139eac1d9c..ffc56533be 100644 --- a/lcl/stdctrls.pp +++ b/lcl/stdctrls.pp @@ -729,7 +729,7 @@ type FOnChange: TNotifyEvent; FSelLength: integer; FSelStart: integer; - FTextChangedByRealSetText: Boolean; + FTextChangedByRealSetTextCounter: Integer; FTextHint: TTranslateString; procedure ShowEmulatedTextHint(const ForceShow: Boolean = False); procedure HideEmulatedTextHint;