T(Float)SpinEdit: make Modified have the correct value in OnChange as well.

This commit is contained in:
Bart 2021-10-03 21:41:34 +02:00
parent 16c42ceaa0
commit 2befd9dd7f
2 changed files with 20 additions and 3 deletions

View File

@ -32,6 +32,17 @@ begin
RegisterCustomFloatSpinEdit;
end;
procedure TCustomFloatSpinEdit.Change;
begin
//This needs to be done here, not in TextChanged, since the WS causes a Change, but not a TextChanged.
if FForceModifiedIsFalseInOnChange then
begin
Modified := False;
FForceModifiedIsFalseInOnChange := False;
end;
inherited Change;
end;
function TCustomFloatSpinEdit.RealGetText: TCaption;
begin
if HandleAllocated then
@ -140,9 +151,12 @@ begin
// clear FValueChanged to prevent getting the old value from the widget
FValueChanged := False;
FUpdatePending := True;
UpdateControl;
Modified := False;
//UpdateControl will trigger an OnChange through the WS code
//Modified will no be reset to True by the WS code, but in this case we need it to be False
if not (csLoading in ComponentState) then
FForceModifiedIsFalseInOnChange := True;
UpdateControl;
if not HandleAllocated
and ([csLoading, csDestroying] * ComponentState = [])
@ -187,7 +201,8 @@ constructor TCustomFloatSpinEdit.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
FCompStyle := csSpinEdit;
FForceModifiedIsFalseInOnChange := False;
FIncrement := DefIncrement;
FDecimals := DefDecimals;
FMaxValue := DefMaxValue;

View File

@ -40,6 +40,7 @@ type
FEditorEnabled: Boolean;
FMaxValue: Double;
FMinValue: Double;
FForceModifiedIsFalseInOnChange: Boolean;
FValue: Double;
FValueEmpty: Boolean;
FUpdatePending: Boolean;
@ -51,6 +52,7 @@ type
function IncrementStored: Boolean;
protected
class procedure WSRegisterClass; override;
procedure Change; override;
function RealGetText: TCaption; override;
procedure RealSetText(const AValue: TCaption); override;
procedure TextChanged; override;