Forum

× General Purpose Components and Libraries, discussions, problems and suggestions

Question TKNumberEdit (and other numeric edits)

  • Fernando
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
More
3 weeks 2 days ago #11781 by Fernando
TKNumberEdit (and other numeric edits) was created by Fernando
Hello,

I was looking for a numeric component capable of entering float numbers, including exponential notation. In delphi, i Had used succesfully orpheus' flexedit, but here it does not work well: in Typhon32, I can put flexedit in a form and use it, but if that form is modal the second time it is shown with ShowModal it looks empty, no controls are painted at all, and it cannot be closed. On Typhon64, dropping flex edit on a form causes de IDE to crash.

Looking for replacements, it was difficult to find a numeric edit which could handle properly exponential notation. The only that I got working in this way is TKNumberEdit, but I found that it accepts exponential numbers like 1.5E5 but not 1.5E-5 nor 1.5E+5. A quick look into the code revealed this, in function TKNumberEdit.InspectInputChar (file kedits.pas), line 1425 and ff:
if neafFloat in FAcceptedFormats then
    begin
      KeyFloat := Key;
      if CharInSetEx(KeyFLoat, ['0'..'9','-', '.', ',', 'e', 'E', DecimalSeparator, #8]) then
      begin
        if (KeyFloat = '-') and (SelStart <> 0) then KeyFloat := #0;
        if CharInSetEx(KeyFLoat, ['.', ',', DecimalSeparator]) and
          ((Pos('.', S) <> 0) or (Pos(',', S) <> 0) or (Pos(DecimalSeparator, S) <> 0)) then
          KeyFloat := #0;
      end else
        KeyFloat := #0;
Albeit 'E' and 'e' are accepted, the problem is in line 1430:
if (KeyFloat = '-') and (SelStart <> 0) then KeyFloat := #0;
This only allows a minus sign as the first character, but not after the 'E' or 'e' (neither a '+' sign is allowed, by the way).
I edited the above fragment as here:
if neafFloat in FAcceptedFormats then
    begin
      KeyFloat := Key;
      if CharInSetEx(KeyFLoat, ['0'..'9','-', '+', '.', ',', 'e', 'E', DecimalSeparator, #8]) then     //added '+'
      begin
        if (KeyFloat = '-') and ((SelStart <> 0) and (UpCase(S[SelStart]) <> 'E')) then KeyFloat := #0;  //added:  "and (UpCase(S[SelStart]) <> 'E')"
        if (KeyFloat = '+') and ((SelStart <> 0) and (UpCase(S[SelStart]) <> 'E')) then KeyFloat := #0;  //new line added
        if CharInSetEx(KeyFLoat, ['.', ',', DecimalSeparator]) and
          ((Pos('.', S) <> 0) or (Pos(',', S) <> 0) or (Pos(DecimalSeparator, S) <> 0)) then
          KeyFloat := #0;
      end else
        KeyFloat := #0;
Now it allows 1.5E5, 1.5E-5 and 1.5E+5 (plus a '+' at the number start), which works well for me.
My question is: is it possible to incorporate this fix into the version of kcontros distributed with CT? I posted this fix in the k controls website (tkweb.eu) but got no answer so far; in fact there seems to be no work ant all on edits in the last years there, so I ask here.
Regards
Fernando

Please Log in or Create an account to join the conversation.

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Away
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
More
3 weeks 2 days ago - 3 weeks 2 days ago #11782 by Sternas Stefanos
Replied by Sternas Stefanos on topic TKNumberEdit (and other numeric edits)
Thanks Sir
we will put your fix to pl_kcontrols for next CT release

CodeTyphon Architect and Programmer
Last edit: 3 weeks 2 days ago by Sternas Stefanos.
The following user(s) said Thank You: Fernando

Please Log in or Create an account to join the conversation.

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Away
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
More
3 weeks 2 days ago #11783 by Sternas Stefanos
Replied by Sternas Stefanos on topic TKNumberEdit (and other numeric edits)
Please try and this LAB CT version

pl_KControls Ver 6.6.1 Source GIT hash : 0dbad6b6449e2cc1ac56e57fb15ca3a245f5ebf4

your fix is now at kedits.pas line: 1264

CodeTyphon Architect and Programmer
Attachments:

Please Log in or Create an account to join the conversation.

  • Fernando
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
More
3 weeks 1 day ago - 3 weeks 1 day ago #11784 by Fernando
Replied by Fernando on topic TKNumberEdit (and other numeric edits)
Hi,

Number input works as expected. But there are two little problems, which seem new:
1. The control has the option neoUseUpDown which causes to display up and down buttons to the right of the control. Setting it to False used to hide the buttons. With this new version, the buttons are always displayed, only are hidden when the user starts typing, if the option is False.

2. In the object inspector there are two new properties, MaxAsInt and MinAsInt (integers) which interact with Max and Min (doubles), trying to keep the same value, which leds to errors if one attempts to set big absolute values in Max and Min (e.g. 1e300 and -1e300). There is a workaround, which is to set the deisred Max and Min dinamically, for example in FormCreate event.

I did not test other controls in the package so far.

Overall, it works, with the nuisance of 1 above.
Last edit: 3 weeks 1 day ago by Fernando.

Please Log in or Create an account to join the conversation.

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Away
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
More
3 weeks 1 day ago #11785 by Sternas Stefanos
Replied by Sternas Stefanos on topic TKNumberEdit (and other numeric edits)
Thanks Sir
we will try to fix and this

CodeTyphon Architect and Programmer

Please Log in or Create an account to join the conversation.