Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » Elevate Web Builder Technical Support » Support Forums » Elevate Web Builder General » View Thread |
Messages 1 to 1 of 1 total |
Using TEdit for number entry |
Thu, Sep 23 2021 8:31 AM | Permanent Link |
Paul Coshott | Hi All,
Using the OnKeyDown event, I have written some code to only allow number entry for a TEdit control, plus left right arrows, home, end, backspace, delete keys etc. I have 2 problems. First I’d like to limit the whole number part to a certain length of characters, and also the decimal part, so I can limit it to 2 decimals for example. And secondly, if I’m at the maximum, but the edit text is selected, I want it to overwrite what’s selected. But currently, it doesn’t. Any chance anyone could improve this code or suggest a better way to do it. function TfOptionsTools.eMCurrentKeyDown(Sender: TObject; Key: Integer; ShiftKey: Boolean; CtrlKey: Boolean; AltKey: Boolean): Boolean; begin if ((Key >= 48) and (Key <= 57)) or ((Key >= 96) and (Key <= 105)) then begin if Pos('.', TEdit(Sender).Text) = 0 then begin Result := Length(TEdit(Sender).Text) <= 1; end else begin Result := Length(TEdit(Sender).Text) <= 3; end; end else if (Key = 110) then begin Result := Pos('.', TEdit(Sender).Text) = 0; end else if (Key = 8) or (Key = 9) or (Key = 37) or (Key = 39) or (Key = 46) then begin Result := True; end else begin Result := False; end; end; Thanks, Paul |
This web page was last updated on Friday, November 1, 2024 at 07:01 PM | Privacy PolicySite Map © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? E-mail us at info@elevatesoft.com |