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; RegisterCustomFloatSpinEdit;
end; 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; function TCustomFloatSpinEdit.RealGetText: TCaption;
begin begin
if HandleAllocated then if HandleAllocated then
@ -140,9 +151,12 @@ begin
// clear FValueChanged to prevent getting the old value from the widget // clear FValueChanged to prevent getting the old value from the widget
FValueChanged := False; FValueChanged := False;
FUpdatePending := True; 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 if not HandleAllocated
and ([csLoading, csDestroying] * ComponentState = []) and ([csLoading, csDestroying] * ComponentState = [])
@ -187,7 +201,8 @@ constructor TCustomFloatSpinEdit.Create(TheOwner: TComponent);
begin begin
inherited Create(TheOwner); inherited Create(TheOwner);
FCompStyle := csSpinEdit; FCompStyle := csSpinEdit;
FForceModifiedIsFalseInOnChange := False;
FIncrement := DefIncrement; FIncrement := DefIncrement;
FDecimals := DefDecimals; FDecimals := DefDecimals;
FMaxValue := DefMaxValue; FMaxValue := DefMaxValue;

View File

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