View Issue Details

IDProjectCategoryView StatusLast Update
0013045LazarusLCLpublic2013-09-03 12:07
ReporterBart Broersma Assigned ToBart Broersma  
PrioritynormalSeverityminorReproducibilityhave not tried
Status closedResolutionfixed 
Platformi386OSWinMe 
Target Version0.9.27 (SVN)Fixed in Version0.9.27 (SVN) 
Summary0013045: TFloatSpinEdit should not accept "invalid keys" as input
DescriptionTFloatSpinEdit accepts any key that you type into the control.
IMO (and as in Delphi 3) it should only accept +,- and digits and not alpha-chars (like a, b, c etc).
Additional InformationOnly tested on win32. Will test Linux some other time.
TagsNo tags attached.
Fixed in Revision18456
LazTarget1.4
WidgetsetWin32/Win64
Attached Files

Relationships

has duplicate 0012176 closedBart Broersma TFloatSpinEdit and TSpinEdit do accept non-numeric characters in the edit box 

Activities

Bart Broersma

2009-01-25 22:35

developer   ~0024761

Last edited: 2009-01-25 22:37

Same for Linux GTK1 (Laz. 0.9.26)
(Cannot test GTK2 ATM)

Paul Ishenin

2009-01-26 11:05

manager   ~0024772

I have fixed 2 related problems. Do you want to fix this one yourself?

Bart Broersma

2009-01-26 13:40

developer   ~0024778

Last edited: 2009-01-26 19:22

I attached a patch based on the following rules:

- Disallow any key that is not a digit, decimalseparator, + or -
- For ease of use translate any decimalpoint or comma to DecimalSeparator
- If FDecimals = 0 (as in TSpinEdit), disallow decimalseparator also

Things could be made more sophisticated like only allow +/- if cursor is at begin of control (and no + or - is present yet), allow DecimalSeparator only if it is not already in the text, but that might be too fancy.
As it is now, it behaves like Delphi 3.

2009-01-26 19:17

 

spinedit.patch (2,218 bytes)   
diff -u -r lclold\include\spinedit.inc lcl\include\spinedit.inc
--- lclold\include\spinedit.inc	Mon Jan 26 19:38:48 2009
+++ lcl\include\spinedit.inc	Mon Jan 26 19:39:22 2009
@@ -5,7 +5,7 @@
  *                                                                           *
  *  This file is part of the Lazarus Component Library (LCL)                 *
  *                                                                           *
- *  See the file COPYING.modifiedLGPL.txt, included in this distribution,        *
+ *  See the file COPYING.modifiedLGPL.txt, included in this distribution,    *
  *  for details about the copyright.                                         *
  *                                                                           *
  *  This program is distributed in the hope that it will be useful,          *
@@ -103,6 +103,22 @@
   inherited Loaded;
   if FUpdatePending then UpdateControl;
 end;
+
+procedure TCustomFloatSpinEdit.KeyPress(var Key: char);
+{Disallow any key that is not a digit, decimalseparator, + or -
+ For ease of use translate any decimalpoint or comma to DecimalSeparator
+ Tab and backSpace ofcourse should be passed onto inherited KeyPress
+ If FDecimals = 0 (as in TSpinEdit), disallow decimalseparator also
+ We could make it more sophisticated and only allow +/- at front,
+ DecimalSeparator only if not already in text, but this way is Delphi compatible
+}
+begin
+  if (Key in ['.',',']) then Key := Decimalseparator;
+  if not (Key in ['0'..'9',DecimalSeparator,'+','-',#8,#9]) then Key := #0;
+  if (Key = DecimalSeparator) and (FDecimals = 0) then Key := #0;
+  inherited KeyPress(Key);
+end;
+
 
 class function TCustomFloatSpinEdit.GetControlClassDefaultSize: TPoint;
 begin
diff -u -r lclold\spin.pp lcl\spin.pp
--- lclold\spin.pp	Mon Jan 26 19:44:32 2009
+++ lcl\spin.pp	Mon Jan 26 19:12:46 2009
@@ -60,6 +60,7 @@
     procedure InitializeWnd; override;
     procedure FinalizeWnd; override;
     procedure Loaded; override;
+    procedure KeyPress(var Key: char); override;
     class function GetControlClassDefaultSize: TPoint; override;
   public
     constructor Create(TheOwner: TComponent); override;
spinedit.patch (2,218 bytes)   

Paul Ishenin

2009-01-27 04:44

manager   ~0024798

Thanks, applied. The only problem with your patches is that they are not in svn (tortoise svn) compatible format :( If you are using svn I believe there is a command to create a patch file.

Please close if ok.

Bart Broersma

2009-02-23 16:11

developer   ~0025675

Fixed.

Issue History

Date Modified Username Field Change
2009-01-25 16:47 Bart Broersma New Issue
2009-01-25 16:47 Bart Broersma LazTarget => -
2009-01-25 16:47 Bart Broersma Widgetset => Win32
2009-01-25 22:35 Bart Broersma Note Added: 0024761
2009-01-25 22:37 Bart Broersma Note Edited: 0024761
2009-01-26 11:05 Paul Ishenin LazTarget - => post 1.2
2009-01-26 11:05 Paul Ishenin Note Added: 0024772
2009-01-26 11:05 Paul Ishenin Status new => feedback
2009-01-26 13:40 Bart Broersma Note Added: 0024778
2009-01-26 19:17 Bart Broersma File Added: spinedit.patch
2009-01-26 19:22 Bart Broersma Note Edited: 0024778
2009-01-26 19:22 Bart Broersma Status feedback => assigned
2009-01-26 19:22 Bart Broersma Assigned To => Bart Broersma
2009-01-27 04:44 Paul Ishenin Fixed in Revision => 18456
2009-01-27 04:44 Paul Ishenin Status assigned => resolved
2009-01-27 04:44 Paul Ishenin Fixed in Version => 0.9.27 (SVN)
2009-01-27 04:44 Paul Ishenin Resolution open => fixed
2009-01-27 04:44 Paul Ishenin Note Added: 0024798
2009-01-27 04:44 Paul Ishenin Target Version => 0.9.27 (SVN)
2009-02-23 16:11 Bart Broersma Status resolved => closed
2009-02-23 16:11 Bart Broersma Note Added: 0025675
2009-02-23 16:57 Bart Broersma Relationship added has duplicate 0012176
2013-09-03 12:07 Martin Friebe LazTarget post 1.2 => 1.4