Page 2 of 2 First 12
  • Jump to page:
    #16
  1. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2006
    Location
    Carlsbad, CA
    Posts
    2,057
    Rep Power
    383
    Actually writing your own TEdit descendant class for this case is not really difficult.
    Agreed.
    TadvEdit handles many other "situations" also. However, I really purchased TMS component set for its great, professional grid components and the Edit and other useful components were a pleasant bonus.
    Probably no compelling reason to have brought it up in this thread

    Clive
  2. #17
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    28
    Rep Power
    0
    Thanks to all for your suggestions..
  4. #18
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    156
    Rep Power
    3
    I decided to put together two articles/tutorials about this matter. You can find them at urls below.

  6. #19
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    156
    Rep Power
    3
    Another tutorial about creating more "powerful" edit control. This time you can limit the edit control into any set of characters, not only numbers. Works in any version of Windows 32/64 bit, and in any version of Delphi for Windows 32/64.
  8. #20
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    19
    Rep Power
    0
    I have brisked this topic and I am unsure exactly what you want to do but if it is like I did why don't you just use onchange (or onexit) with

    Try
    Strtoint(edit.text);
    Except
    edit.text:='0';
    end;

    It will fail on all but numbers.
  10. #21
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    8
    Rep Power
    0
    Originally Posted by majlumbo
    Right clicking and selecting paste will allow non-numeric data to be pasted into the control. I've used this before, but it just doesn't cover all the possibilities.
    in combination with code previously described just use this:

    procedure TForm1.Edit1ContextPopup(Sender: TObject; MousePos: TPoint; var Handled: Boolean);
    begin
    Handled:= True;
    end;

    That will prevent edit control popup menu to appear. I do this and work perfectly for me.
  12. #22
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    356
    Rep Power
    7
    Originally Posted by dakijevski
    in combination with code previously described just use this:

    procedure TForm1.Edit1ContextPopup(Sender: TObject; MousePos: TPoint; var Handled: Boolean);
    begin
    Handled:= True;
    end;

    That will prevent edit control popup menu to appear. I do this and work perfectly for me.
    You still have Ctrl-V and I think Ctrl-Ins also works, so pasting into the edit control is still possible. My point wasn't that handling Keypress isn't adequate, it just isn't fool proof. The only real option is to disable all forms of pasting into a Numeric Edit, which wouldn't be optimal for a user.

    Try
    Strtoint(edit.text);
    Except
    edit.text:='0';
    end;
    You state "It will fail on all but numbers." but it will also fail on a number that is one more or one less than what an Int64 will hold, so you can presumably have a "valid" number that is rejected with this code.
  14. #23
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    8
    Rep Power
    0
    Originally Posted by majlumbo
    You still have Ctrl-V and I think Ctrl-Ins also works, so pasting into the edit control is still possible.
    I think you are wrong. I just checked again. Only numbers 0-9, delete and backspace working in this way. All other keys are blocked.

    if not( Key in ['0'..'9'] +[#13,#8]) then
    Key := #0;
  16. #24
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    356
    Rep Power
    7
    Originally Posted by dakijevski
    I think you are wrong. I just checked again. Only numbers 0-9, delete and backspace working in this way. All other keys are blocked.
    Copy this line and paste it into that same edit control and you'll see that I am not wrong...

    Keydown is Only triggered on a Keydown event, and pressing Ctrl-V does not trigger a keydown event.
  18. #25
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    8
    Rep Power
    0
    Originally Posted by majlumbo
    Copy this line and paste it into that same edit control and you'll see that I am not wrong...

    Keydown is Only triggered on a Keydown event, and pressing Ctrl-V does not trigger a keydown event.
    Procedure is OnKeyPress, but OK. Whatever.
Page 2 of 2 First 12
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo