Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

input screening

Status
Not open for further replies.

med79

Instructor
Sep 6, 2003
2
IR

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.

Andrew
 

Thanks, I'll try that and let you know.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top