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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delphi 4 "if trim(edit1.text)=....." -is integer? 4

Status
Not open for further replies.

minchite

Programmer
Oct 19, 2001
1
0
0
IT
i need the correct syntax to ask delphi 4 if an edit.text is an integer value.
Please help me. Thanks.
 
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;


obs: this is only for positive integers

Regards S. van Els
SAvanEls@cq-link.sr
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top