View Issue Details

IDProjectCategoryView StatusLast Update
0021639LazarusWidgetsetpublic2012-06-03 15:11
ReportercobinesAssigned ToBart Broersma 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
PlatformWin32OSWindows XPOS VersionSP3
Product Version0.9.31 (SVN)Product Build36507 
Target VersionFixed in Version1.1 (SVN) 
Summary0021639: SpinEdit fires OnChange when losing focus even though value has not changed
DescriptionRun attached example, click on the second spin edit, then on first, then on second, then on first... In the console there will be OnChange messages printed, even though the values are not being changed.
This doesn't happen with 0.9.30.
Also this does not happen with 0.9.31 in Linux with LCLGTK2 and LCLQT4.
TagsNo tags attached.
Fixed in Revisionr37500
LazTarget-
WidgetsetWin32/Win64
Attached Files
  • spin_edit_on_exit_change.zip (2,024 bytes)
  • set_text_only_if_different.diff (2,229 bytes)
    Index: lcl/interfaces/win32/win32wsspin.pp
    ===================================================================
    --- lcl/interfaces/win32/win32wsspin.pp	(revision 37355)
    +++ lcl/interfaces/win32/win32wsspin.pp	(working copy)
    @@ -72,9 +72,11 @@
       end;
     
     procedure UpdateFloatSpinEditControl(const Handle: HWND;
    -  const AFloatSpinEdit: TCustomFloatSpinEdit);
    +  const AFloatSpinEdit: TCustomFloatSpinEdit;
    +  AlwaysSetText: Boolean = True);
     procedure UpdateFloatSpinEditText(const ASpinEdit: TCustomFloatSpinEdit;
    -  const ANewValue: Double);
    +  const ANewValue: Double;
    +  AlwaysSetText: Boolean = True);
     
     implementation
     
    @@ -106,7 +108,7 @@
       Result := WindowProc(Window, Msg, WParam, LParam);
       // after generic window proc
       if Msg = WM_KILLFOCUS then
    -    UpdateFloatSpinEditControl(Window, TCustomFloatSpinEdit(GetWin32WindowInfo(Window)^.WinControl));
    +    UpdateFloatSpinEditControl(Window, TCustomFloatSpinEdit(GetWin32WindowInfo(Window)^.WinControl), False);
     end;
     
     function SpinUpDownWndProc(Window: HWnd; Msg: UInt; WParam: Windows.WParam;
    @@ -125,7 +127,8 @@
     end;
     
     procedure UpdateFloatSpinEditControl(const Handle: HWND;
    -  const AFloatSpinEdit: TCustomFloatSpinEdit);
    +  const AFloatSpinEdit: TCustomFloatSpinEdit;
    +  AlwaysSetText: Boolean = True);
     var
       lWindowInfo: PWin32WindowInfo;
     begin
    @@ -133,17 +136,19 @@
       if lWindowInfo <> @DefaultWindowInfo then
       begin
         lWindowInfo^.spinValue := AFloatSpinEdit.Value;
    -    UpdateFloatSpinEditText(AFloatSpinEdit, AFloatSpinEdit.Value);
    +    UpdateFloatSpinEditText(AFloatSpinEdit, AFloatSpinEdit.Value, AlwaysSetText);
       end;
     end;
     
     procedure UpdateFloatSpinEditText(const ASpinEdit: TCustomFloatSpinEdit;
    -  const ANewValue: Double);
    +  const ANewValue: Double;
    +  AlwaysSetText: Boolean = True);
     var
       newValueText: string;
     begin
       newValueText := ASpinEdit.ValueToStr(ANewValue);
    -  Windows.SendMessage(ASpinEdit.Handle, WM_SETTEXT, 0, Windows.LPARAM(PChar(newValueText)));
    +  if AlwaysSetText or (ASpinEdit.Text <> newValueText) then
    +    Windows.SendMessage(ASpinEdit.Handle, WM_SETTEXT, 0, Windows.LPARAM(PChar(newValueText)));
     end;
     
     class function TWin32WSCustomFloatSpinEdit.CreateHandle(const AWinControl: TWinControl;
    

Activities

2012-04-03 08:10

 

spin_edit_on_exit_change.zip (2,024 bytes)

2012-05-19 22:14

 

set_text_only_if_different.diff (2,229 bytes)
Index: lcl/interfaces/win32/win32wsspin.pp
===================================================================
--- lcl/interfaces/win32/win32wsspin.pp	(revision 37355)
+++ lcl/interfaces/win32/win32wsspin.pp	(working copy)
@@ -72,9 +72,11 @@
   end;
 
 procedure UpdateFloatSpinEditControl(const Handle: HWND;
-  const AFloatSpinEdit: TCustomFloatSpinEdit);
+  const AFloatSpinEdit: TCustomFloatSpinEdit;
+  AlwaysSetText: Boolean = True);
 procedure UpdateFloatSpinEditText(const ASpinEdit: TCustomFloatSpinEdit;
-  const ANewValue: Double);
+  const ANewValue: Double;
+  AlwaysSetText: Boolean = True);
 
 implementation
 
@@ -106,7 +108,7 @@
   Result := WindowProc(Window, Msg, WParam, LParam);
   // after generic window proc
   if Msg = WM_KILLFOCUS then
-    UpdateFloatSpinEditControl(Window, TCustomFloatSpinEdit(GetWin32WindowInfo(Window)^.WinControl));
+    UpdateFloatSpinEditControl(Window, TCustomFloatSpinEdit(GetWin32WindowInfo(Window)^.WinControl), False);
 end;
 
 function SpinUpDownWndProc(Window: HWnd; Msg: UInt; WParam: Windows.WParam;
@@ -125,7 +127,8 @@
 end;
 
 procedure UpdateFloatSpinEditControl(const Handle: HWND;
-  const AFloatSpinEdit: TCustomFloatSpinEdit);
+  const AFloatSpinEdit: TCustomFloatSpinEdit;
+  AlwaysSetText: Boolean = True);
 var
   lWindowInfo: PWin32WindowInfo;
 begin
@@ -133,17 +136,19 @@
   if lWindowInfo <> @DefaultWindowInfo then
   begin
     lWindowInfo^.spinValue := AFloatSpinEdit.Value;
-    UpdateFloatSpinEditText(AFloatSpinEdit, AFloatSpinEdit.Value);
+    UpdateFloatSpinEditText(AFloatSpinEdit, AFloatSpinEdit.Value, AlwaysSetText);
   end;
 end;
 
 procedure UpdateFloatSpinEditText(const ASpinEdit: TCustomFloatSpinEdit;
-  const ANewValue: Double);
+  const ANewValue: Double;
+  AlwaysSetText: Boolean = True);
 var
   newValueText: string;
 begin
   newValueText := ASpinEdit.ValueToStr(ANewValue);
-  Windows.SendMessage(ASpinEdit.Handle, WM_SETTEXT, 0, Windows.LPARAM(PChar(newValueText)));
+  if AlwaysSetText or (ASpinEdit.Text <> newValueText) then
+    Windows.SendMessage(ASpinEdit.Handle, WM_SETTEXT, 0, Windows.LPARAM(PChar(newValueText)));
 end;
 
 class function TWin32WSCustomFloatSpinEdit.CreateHandle(const AWinControl: TWinControl;

cobines

2012-05-19 22:14

reporter   ~0059770

Uploaded patch.

Bart Broersma

2012-05-31 19:32

developer   ~0060091

@cobines,

Why not only this little change in UpdateFloatSpinEditText():

procedure UpdateFloatSpinEditText(const ASpinEdit: TCustomFloatSpinEdit;
  const ANewValue: Double);
var
  newValueText: string;
begin
  newValueText := ASpinEdit.ValueToStr(ANewValue);
  if (newValuetext <> ASpinEdit.Text) then
    Windows.SendMessage(ASpinEdit.Handle, WM_SETTEXT, 0, Windows.LPARAM(PChar(newValueText)));
end;

Is there a scenario in which this will fail?

Bart Broersma

2012-06-03 15:10

developer   ~0060222

I applied my modification to your patch (see note 0060091).
Please test and close if OK.

Issue History

Date Modified Username Field Change
2012-04-03 08:10 cobines New Issue
2012-04-03 08:10 cobines File Added: spin_edit_on_exit_change.zip
2012-04-03 08:10 cobines Widgetset => Win32/Win64
2012-04-04 16:19 Bart Broersma LazTarget => -
2012-04-04 16:19 Bart Broersma Status new => confirmed
2012-05-19 22:14 cobines File Added: set_text_only_if_different.diff
2012-05-19 22:14 cobines Note Added: 0059770
2012-05-20 01:53 Maxim Ganetsky Status confirmed => assigned
2012-05-20 01:53 Maxim Ganetsky Assigned To => Bart Broersma
2012-05-31 19:32 Bart Broersma Note Added: 0060091
2012-05-31 19:32 Bart Broersma Status assigned => feedback
2012-06-03 15:10 Bart Broersma Fixed in Revision => r37500
2012-06-03 15:10 Bart Broersma Status feedback => resolved
2012-06-03 15:10 Bart Broersma Fixed in Version => 1.1 (SVN)
2012-06-03 15:10 Bart Broersma Resolution open => fixed
2012-06-03 15:10 Bart Broersma Note Added: 0060222