For Newbie

Tuesday, 15 November 2011

Check the input character is numeric or not by Delphi



Error handler using the try - except. Function declaration:
isnumber function (n: String): Boolean;
begin
   try
     StrToInt (n);
     Result: = True;
   except
     Result: = False;
   end;
end;

If the input is numeric, then the result is True and False if it is not worth the result.

implementation:
procedure TForm1.Button1Click (Sender: TObject);
begin
   if isnumber (Edit1.Text) then ShowMessage ('Input is numeric! ")
   else ShowMessage ('Input not a number!');
end;

As proof, run through the debugger without Delphi (compile and run the exe file that has been finished).

Share on Facebook
Share on Twitter
Share on Google+

Related : Check the input character is numeric or not by Delphi