View Issue Details

IDProjectCategoryView StatusLast Update
0015904LazarusLCLpublic2010-10-06 12:40
ReporterVitaly YakuninAssigned ToBart Broersma 
PrioritynormalSeveritymajorReproducibilityalways
Status closedResolutionfixed 
Product Version0.9.29 (SVN)Product Build 
Target VersionFixed in Version0.9.29 (SVN) 
Summary0015904: [patch] TFloatSpinEdit.OnKeyPress: Key = only "0".."9", "-" & DecimalSeparator
DescriptionThis is a bug or a feature?
Pressing any other key, except those specified in the header, the parameter "Key" is set to #0.
TagsNo tags attached.
Fixed in Revision27585
LazTarget0.9.30
Widgetset
Attached Files
  • spinedit.inc.keypress.diff (604 bytes)
    Index: spinedit.inc
    ===================================================================
    --- spinedit.inc	(revision 22593)
    +++ spinedit.inc	(working copy)
    @@ -110,10 +110,10 @@
      DecimalSeparator only if not already in text, but this way is Delphi compatible
     }
     begin
    +  inherited KeyPress(Key);
       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;
    

Activities

Bart Broersma

2010-03-06 16:32

developer   ~0034974

This is a feauture (by me).
You should not be able to type anything except floats into the control.

Vitaly Yakunin

2010-03-06 17:11

reporter   ~0034976

Last edited: 2010-03-06 17:43

I agree with the restrictions, but only in order not to appear strange characters editor field. Event (OnKeyPress), at my discretion, should correctly report the object that caused it (Key).
Example. I need that when you click on "Enter" koponent self destruct.

2010-03-06 23:48

 

spinedit.inc.keypress.diff (604 bytes)
Index: spinedit.inc
===================================================================
--- spinedit.inc	(revision 22593)
+++ spinedit.inc	(working copy)
@@ -110,10 +110,10 @@
  DecimalSeparator only if not already in text, but this way is Delphi compatible
 }
 begin
+  inherited KeyPress(Key);
   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;

Bart Broersma

2010-03-06 23:49

developer   ~0034996

Attached diff should fix it.
Inherited Keypress was called after changing the key, now it is before.

Vitaly Yakunin

2010-03-07 09:12

reporter   ~0034998

Thanks for the patch. I think this realization is correct. Will this change added in the next SVN?

Bart Broersma

2010-03-07 14:42

developer   ~0035010

When one of the managers applies the patch (they are very busy).
Don't worry it'll be picked up.
In the mean time you can change your local copy (then rebuild LCL).

Vitaly Yakunin

2010-03-07 20:02

reporter   ~0035018

At home I have already corrected. I hope that this will be the default.

Luiz Americo

2010-04-01 18:28

developer   ~0036381

I tested with Delphi and OnKeyPress is called only when ESC, DecimalSeparator and numbers are pressed.

I used the following code:

procedure TForm1.SpinEdit1KeyPress(Sender: TObject; var Key: Char);
var
  KeyValue: String;
begin
  case Key of
    0000013: KeyValue := 'RET';
    0000008: KeyValue := 'ESC';
  else
    if Key = DecimalSeparator then
      KeyValue := 'SEP'
    else
      KeyValue := Key;
  end;
  Caption := Caption + KeyValue;
end;

Bart Broersma

2010-05-04 18:33

developer   ~0037260

@Luiz: I consider that a design flaw in Delphi (but hen, who the *** am I to judge).
OnKeyPress is (generally speaking) supposed to give the programmer access to the pressed key _before_ that key is handled by the control (and alter the key if he/she sees fit).

(It would still be rather easy to implement it that way, if we really want)

Can any of the core-members give his/her opinion?

Zeljan Rikalo

2010-05-04 19:05

developer   ~0037261

personally, I see it as good feature, since you can have control which can accept letters also (for some reason), and then you can change Key acceptable value for TSpinEdits KeyPress .... but let other devels says something about this too.
I don't see any harm here since wrong key will be nulled anyway.

Vitaly Yakunin

2010-05-06 08:32

reporter   ~0037317

Bart diff file is correctly allows the developer to track click clave. And do not deprive the security component of Invalid input data.

Vitaly Yakunin

2010-08-09 22:07

reporter   ~0040091

What's new on this issue?

Bart Broersma

2010-08-09 22:58

developer   ~0040093

Just waiting for one af the managers to apply or dismiss.
Have patience.

Vitaly Yakunin

2010-10-05 12:01

reporter   ~0041504

Can be closed. Now, this component is not using. Wrote for a similar component.

Maxim Ganetsky

2010-10-05 22:19

developer   ~0041522

@Bart: should this patch still be applied?

Bart Broersma

2010-10-05 23:23

developer   ~0041526

@Maxim: yes it should still be applied.
As a general rule inherited Keypress should be called before processing the key in KeyPressed, giving the user th eopportunity to change the key in the OnKeyPressed event.

When I first wrote the code for Keypressed, I just did this wrong (in fact it was sloppy coding).

Maxim Ganetsky

2010-10-05 23:37

developer   ~0041527

Last edited: 2010-10-05 23:45

Applied in r27585, thanks.

@Bart: I recommend to set LazTarget field for bugs with patches to the nearest Lazarus release (as I did in this case) and to remind about them in mailing lists from time to time, so they will be applied faster. ;)

Note that this bug was simply lost among lots of other ones.

Vitaly Yakunin

2010-10-06 12:39

reporter   ~0041539

Thanks

Vitaly Yakunin

2010-10-06 12:40

reporter   ~0041540

Fixed

Issue History

Date Modified Username Field Change
2010-03-06 16:12 Vitaly Yakunin New Issue
2010-03-06 16:32 Bart Broersma Note Added: 0034974
2010-03-06 17:11 Vitaly Yakunin Note Added: 0034976
2010-03-06 17:43 Vitaly Yakunin Note Edited: 0034976
2010-03-06 23:47 Bart Broersma Status new => assigned
2010-03-06 23:47 Bart Broersma Assigned To => Bart Broersma
2010-03-06 23:48 Bart Broersma File Added: spinedit.inc.keypress.diff
2010-03-06 23:49 Bart Broersma Note Added: 0034996
2010-03-07 09:12 Vitaly Yakunin Note Added: 0034998
2010-03-07 14:42 Bart Broersma Note Added: 0035010
2010-03-07 20:02 Vitaly Yakunin Note Added: 0035018
2010-04-01 18:28 Luiz Americo Note Added: 0036381
2010-05-04 18:33 Bart Broersma Note Added: 0037260
2010-05-04 19:05 Zeljan Rikalo Note Added: 0037261
2010-05-06 08:32 Vitaly Yakunin Note Added: 0037317
2010-08-09 22:07 Vitaly Yakunin Note Added: 0040091
2010-08-09 22:58 Bart Broersma Note Added: 0040093
2010-10-05 12:01 Vitaly Yakunin Note Added: 0041504
2010-10-05 22:19 Maxim Ganetsky Note Added: 0041522
2010-10-05 22:20 Maxim Ganetsky LazTarget => 0.9.30
2010-10-05 22:20 Maxim Ganetsky Summary TFloatSpinEdit.OnKeyPress: Key = only "0".."9", "-" & DecimalSeparator => [patch] TFloatSpinEdit.OnKeyPress: Key = only "0".."9", "-" & DecimalSeparator
2010-10-05 23:23 Bart Broersma Note Added: 0041526
2010-10-05 23:37 Maxim Ganetsky Fixed in Revision => 27585
2010-10-05 23:37 Maxim Ganetsky Status assigned => resolved
2010-10-05 23:37 Maxim Ganetsky Fixed in Version => 0.9.29 (SVN)
2010-10-05 23:37 Maxim Ganetsky Resolution open => fixed
2010-10-05 23:37 Maxim Ganetsky Note Added: 0041527
2010-10-05 23:39 Maxim Ganetsky Note Edited: 0041527
2010-10-05 23:45 Maxim Ganetsky Note Edited: 0041527
2010-10-06 12:39 Vitaly Yakunin Note Added: 0041539
2010-10-06 12:40 Vitaly Yakunin Status resolved => closed
2010-10-06 12:40 Vitaly Yakunin Note Added: 0041540