You want to enter only numbers in the edit field?
select the onkeypress event:
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if ((Key < '0') or (Key > '9')) and (Key <> #13) then
key := #0; //backspace
end;
You could use the StrToInt function which converts a string to and integer. If the string does not contain a valid integer representation then an exception will be thrown which will let your program know that the text is not an integer value.
Both of these are good suggestions depending on what you want. The first will make it impossible for a user to even type a non-numeric character into the edit box. The other will let you know if they have used non-numeric characters after they have entered the data.
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.