Welcome, Guest
Username: Password: Remember me
General Purpose Components and Libraries, discussions, problems and suggestions
  • Page:
  • 1

TOPIC:

TKNumberEdit (and other numeric edits) 6 years 4 months ago #11781

  • Fernando
  • Fernando's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 66
  • Thank you received: 0
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.

TKNumberEdit (and other numeric edits) 6 years 4 months ago #11782

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Offline
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
  • Posts: 4535
  • Thank you received: 1114
Thanks Sir
we will put your fix to pl_kcontrols for next CT release
PilotLogic Architect and Core Programmer
The following user(s) said Thank You: Fernando

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

Last edit: by Sternas Stefanos.

TKNumberEdit (and other numeric edits) 6 years 4 months ago #11783

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Offline
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
  • Posts: 4535
  • Thank you received: 1114
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
PilotLogic Architect and Core Programmer

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

TKNumberEdit (and other numeric edits) 6 years 4 months ago #11784

  • Fernando
  • Fernando's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 66
  • Thank you received: 0
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.

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

Last edit: by Fernando.

TKNumberEdit (and other numeric edits) 6 years 4 months ago #11785

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Offline
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
  • Posts: 4535
  • Thank you received: 1114
Thanks Sir
we will try to fix and this
PilotLogic Architect and Core Programmer

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

TKNumberEdit (and other numeric edits) 6 years 2 months ago #12673

  • Fernando
  • Fernando's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 66
  • Thank you received: 0
Hello Sternas,

Revisiting the item 1 in my post above, I was able to fix it as follows: in the procedure TKCustomNumberEdit.SetOptions (line 1596 and ff of current lab version of kedits.pas) I added a line to change the Visible status of the UpDown part of the control. The corrected procedure is:
procedure TKCustomNumberEdit.SetOptions(AValue: TKNumberEditOptions);
begin
  if FOptions <> AValue then
  begin
    TextToValue;
    FOptions := AValue;
    UpdateLabel;
    UpdateMaxMin;
    ValueToText;
    FUpDown.Visible:= (neoUseUpDown in AValue);    //added to fix bug: UpDown visible after changing option to do not use
  end;
end;

With this fix, this control is working well for me.
Regards

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

TKNumberEdit (and other numeric edits) 6 years 2 months ago #12675

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Offline
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
  • Posts: 4535
  • Thank you received: 1114
Thanks Sir
we add your fix to LAB CT
PilotLogic Architect and Core Programmer
The following user(s) said Thank You: Fernando

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

  • Page:
  • 1