mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-06-18 09:08:19 +02:00
TCustomEdit: Dont set Modified to True in TextChanged when text is set by code. (Issue #0025666)
git-svn-id: trunk@45617 -
This commit is contained in:
parent
33ebf1adac
commit
08e38d3746
@ -76,6 +76,7 @@ begin
|
||||
BorderStyle := bsSingle;
|
||||
FAutoSelect := True;
|
||||
FAutoSelected := False;
|
||||
FTextChangedByRealSetText := False;
|
||||
AutoSize := True;
|
||||
// Accessibility
|
||||
AccessibleRole := larTextEditorSingleline;
|
||||
@ -499,8 +500,10 @@ end;
|
||||
|
||||
procedure TCustomEdit.RealSetText(const AValue: TCaption);
|
||||
begin
|
||||
inherited RealSetText(AValue);
|
||||
FTextChangedByRealSetText := True;
|
||||
Modified := False;
|
||||
inherited RealSetText(AValue);
|
||||
FTextChangedByRealSetText := False;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
@ -539,6 +542,7 @@ begin
|
||||
begin
|
||||
if ([csLoading,csDestroying]*ComponentState=[]) then
|
||||
begin
|
||||
if not FTextChangedByRealSetText then
|
||||
Modified := True;
|
||||
Change;
|
||||
end;
|
||||
|
@ -185,11 +185,15 @@ const
|
||||
FMaskIsPushed : Boolean;
|
||||
FSavedMask : TInternalMask;
|
||||
FSavedMaskLength : Integer;
|
||||
FTextChangedBySetText: Boolean;
|
||||
FInSetInheritedText: Boolean;
|
||||
|
||||
procedure ClearInternalMask(out AMask: TInternalMask; out ALengthIndicator: Integer);
|
||||
procedure AddToMask(Value: TUtf8Char);
|
||||
function GetModified: Boolean;
|
||||
procedure SetMask(Value : String);
|
||||
function GetIsMasked : Boolean;
|
||||
procedure SetModified(AValue: Boolean);
|
||||
procedure SetSpaceChar(Value : Char);
|
||||
|
||||
procedure SetCursorPos;
|
||||
@ -261,6 +265,7 @@ const
|
||||
constructor Create(TheOwner : TComponent); override;
|
||||
procedure Clear;
|
||||
procedure ValidateEdit; virtual;
|
||||
property Modified: Boolean read GetModified write SetModified;
|
||||
property Text: TCaption read GetText write SetText;
|
||||
end;
|
||||
|
||||
@ -444,6 +449,8 @@ constructor TCustomMaskEdit.Create(TheOwner: TComponent);
|
||||
begin
|
||||
Inherited Create(TheOwner);
|
||||
FSettingInitialText := False;
|
||||
FTextChangedBySetText := False;
|
||||
FInSetInheritedText := False;
|
||||
FRealMask := '';
|
||||
ClearInternalMask(FMask, FMaskLength);
|
||||
ClearInternalMask(FSavedMask, FSavedMaskLength);
|
||||
@ -473,6 +480,25 @@ begin
|
||||
FMask[FMaskLength] := Value;
|
||||
end;
|
||||
|
||||
function TCustomMaskEdit.GetModified: Boolean;
|
||||
begin
|
||||
//This will make Modified = False inside OnChange when text is set by code
|
||||
//TCustomEdit.RealSetText sets Modified to False.
|
||||
//We handle all input in SetInheritedText (which eventually calls RealSetText),
|
||||
//so inside SetInheritedText Modified must be True,
|
||||
//unless we called SetInheritedText from SetText, in that case it must be False,
|
||||
//in all other cases just return inherited value
|
||||
if FTextChangedBySetText then
|
||||
Result := False
|
||||
else
|
||||
begin
|
||||
if FInSetInheritedText then
|
||||
Result := True
|
||||
else
|
||||
Result := inherited Modified;
|
||||
end;
|
||||
end;
|
||||
|
||||
// Prepare the real internal Mask
|
||||
procedure TCustomMaskEdit.SetMask(Value : String);
|
||||
Var
|
||||
@ -658,6 +684,11 @@ begin
|
||||
Result := (FMaskLength > 0);
|
||||
end;
|
||||
|
||||
procedure TCustomMaskEdit.SetModified(AValue: Boolean);
|
||||
begin
|
||||
inherited Modified := AValue;
|
||||
end;
|
||||
|
||||
|
||||
// Set the current Space Char
|
||||
procedure TCustomMaskEdit.SetSpaceChar(Value : Char);
|
||||
@ -938,6 +969,7 @@ procedure TCustomMaskEdit.SetInheritedText(const Value: TCaption);
|
||||
begin
|
||||
if (Value <> Inherited Text) then
|
||||
begin
|
||||
FInSetInheritedText := True;
|
||||
FChangeAllowed := True;
|
||||
FCurrentText := Value;
|
||||
//protect resetting FChangeAllowed := False against unhandled exceptions in user's
|
||||
@ -946,6 +978,7 @@ begin
|
||||
Inherited Text := Value;
|
||||
finally
|
||||
FChangeAllowed := False;
|
||||
FInSetInheritedText := False;
|
||||
end;//finally
|
||||
end;
|
||||
end;
|
||||
@ -1280,6 +1313,8 @@ Begin
|
||||
end;
|
||||
if IsMasked then
|
||||
begin
|
||||
try
|
||||
FTextChangedBySetText := True;
|
||||
if (Value = '') then
|
||||
begin
|
||||
Clear;
|
||||
@ -1418,6 +1453,9 @@ Begin
|
||||
end;
|
||||
end;//FMaskSave = False
|
||||
SetInheritedText(S);
|
||||
finally
|
||||
FTextChangedBySetText := False;
|
||||
end; //try..finally
|
||||
end//Ismasked
|
||||
else
|
||||
begin//not IsMasked
|
||||
|
@ -700,6 +700,7 @@ type
|
||||
FOnChange: TNotifyEvent;
|
||||
FSelLength: integer;
|
||||
FSelStart: integer;
|
||||
FTextChangedByRealSetText: Boolean;
|
||||
procedure SetAlignment(const AValue: TAlignment);
|
||||
function GetCanUndo: Boolean;
|
||||
function GetModified: Boolean;
|
||||
|
Loading…
Reference in New Issue
Block a user