I am using delphi 7. I want to disable all charcter keys on the keyboard when users are filling out a page number field in one of my forms, so they are forced to only type integers.
This is quite easy to do. Create a KeyPress event handler for your numeric TEdit field(s) as follows:
Code:
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
const
BackSpace = #8;
Numerics = [ '0'..'9', BackSpace ];
begin
if not ( key in Numerics ) then
key := #0;
end;
Your user will only be able to enter the characters '0' to '9' or the backspace key. They will still be able to use the tab and cursor control keys. If you want them to be able to use the Return key then you need to add that to the Numerics set.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.