Merged revision(s) 56181 #c5637ad72a from trunk:

Fix firing an OnChange and setting Modified when setting Text inside OnChange and new Text = old Text. Issue #0032602.
........

git-svn-id: branches/fixes_1_8@56239 -
This commit is contained in:
maxim 2017-10-29 22:16:55 +00:00
parent 643398e6f9
commit 8e9ba054d3
3 changed files with 11 additions and 6 deletions

View File

@ -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;

View File

@ -8269,7 +8269,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);

View File

@ -727,7 +727,7 @@ type
FOnChange: TNotifyEvent;
FSelLength: integer;
FSelStart: integer;
FTextChangedByRealSetText: Boolean;
FTextChangedByRealSetTextCounter: Integer;
FTextHint: TTranslateString;
function GetTextHintFontColor: TColor; //Remove in 1.9
function GetTextHintFontStyle: TFontStyles; //Remove in 1.9