View Issue Details

IDProjectCategoryView StatusLast Update
0032793LazarusLCLpublic2019-09-29 12:46
ReporterBart BroersmaAssigned ToBart Broersma 
PrioritynormalSeverityminorReproducibilityhave not tried
Status closedResolutionfixed 
Platformi386OSWin10-64OS Version
Product Version1.9 (SVN)Product Buildr56186 
Target VersionFixed in Version2.0.6 
Summary0032793: Strange behaviour of TSpinEdit when Value = MaxInt and then increment
DescriptionIf a TSpinEdit is not limited (e.i. MaxValue=MinValue) and you set Value to MaxInt and then you click the increment spinner the text in the control changes from 2147483647 to 2147483648, but when querying Value, it will report -2147483648.
This process continues when you further increment the SpinEdit.

SpinEdit1: Text = 2147483648, Value = -2147483648
SpinEdit1: Text = 2147483649, Value = -2147483647
SpinEdit1: Text = 2147483650, Value = -2147483646
SpinEdit1: Text = 2147483651, Value = -2147483645
SpinEdit1: Text = 2147483652, Value = -2147483644
Steps To ReproduceBuild and run attached demo.
Click Button1
Click the up spinner of the SpinEdit, click the speedbutton with caption '?'
Repeat this.

(Never mind the other controls on the demo, I was testing T(Float)SpinEditEx when I encountered this.)
Additional InformationThe internal value of a TSpinEdit is of type Double.
This is the root cause of the discrepancy between text and value.
TagsNo tags attached.
Fixed in Revisionr61945
LazTarget2.0.6
Widgetset
Attached Files
  • sp.zip (66,066 bytes)
  • spinedit.maxint.diff (778 bytes)
    Index: lcl/include/spinedit.inc
    ===================================================================
    --- lcl/include/spinedit.inc	(revision 59686)
    +++ lcl/include/spinedit.inc	(working copy)
    @@ -237,8 +237,28 @@
     end;
     
     function TCustomSpinEdit.GetValue: integer;
    +var
    +  D: Double;
    +  ValueOutOfBound: Boolean;
     begin
    -  Result:=round(inherited GetValue);
    +  D := inherited GetValue;
    +  if (D > MaxInt) then
    +  begin
    +    D := MaxInt;
    +    ValueOutOfBound := True;
    +  end
    +  else
    +  if (D < Low(Integer)) then
    +  begin
    +    D := Low(Integer);
    +    ValueOutOfBound := True;
    +  end;
    +  Result:=round(D);
    +  if ValueOutOfBound then
    +  begin
    +    FValue := Result;
    +    Text := IntToStr(Result);
    +  end;
     end;
     
     procedure TCustomSpinEdit.SetIncrement(const AValue: integer);
    
    spinedit.maxint.diff (778 bytes)

Activities

Bart Broersma

2017-12-07 19:28

developer  

sp.zip (66,066 bytes)

Bart Broersma

2018-12-16 17:07

developer  

spinedit.maxint.diff (778 bytes)
Index: lcl/include/spinedit.inc
===================================================================
--- lcl/include/spinedit.inc	(revision 59686)
+++ lcl/include/spinedit.inc	(working copy)
@@ -237,8 +237,28 @@
 end;
 
 function TCustomSpinEdit.GetValue: integer;
+var
+  D: Double;
+  ValueOutOfBound: Boolean;
 begin
-  Result:=round(inherited GetValue);
+  D := inherited GetValue;
+  if (D > MaxInt) then
+  begin
+    D := MaxInt;
+    ValueOutOfBound := True;
+  end
+  else
+  if (D < Low(Integer)) then
+  begin
+    D := Low(Integer);
+    ValueOutOfBound := True;
+  end;
+  Result:=round(D);
+  if ValueOutOfBound then
+  begin
+    FValue := Result;
+    Text := IntToStr(Result);
+  end;
 end;
 
 procedure TCustomSpinEdit.SetIncrement(const AValue: integer);
spinedit.maxint.diff (778 bytes)

Bart Broersma

2018-12-16 17:08

developer   ~0112611

Ugly workaround attached.
It fixes Value in this case and updates Text accordingly, upon querying Value property.

Issue History

Date Modified Username Field Change
2017-12-07 19:25 Bart Broersma New Issue
2017-12-07 19:28 Bart Broersma File Added: sp.zip
2018-12-16 17:07 Bart Broersma File Added: spinedit.maxint.diff
2018-12-16 17:08 Bart Broersma Note Added: 0112611
2019-09-29 12:22 Bart Broersma Assigned To => Bart Broersma
2019-09-29 12:22 Bart Broersma Status new => resolved
2019-09-29 12:22 Bart Broersma Resolution open => fixed
2019-09-29 12:22 Bart Broersma Fixed in Version => 2.0.6
2019-09-29 12:22 Bart Broersma Fixed in Revision => r61945
2019-09-29 12:22 Bart Broersma LazTarget - => 2.0.6
2019-09-29 12:46 Bart Broersma Status resolved => closed