validation of input integer number in TEdit box

validation of input integer number in TEdit box

validation of input integer number in TEdit box

Check validation of input integer number in TEdit box and format it into two decimal places.

DownloadDownload This Tutorials

Bookmark:

validation of input integer number in TEdit box

Check validation of input integer number in TEdit box and format it into two decimal places.

Demonstrates how to validate of input integer number in TEdit box in Delphi

In order to check the validation, its better to write procedure. So you can call this procedure for all the Edit components within your project.

procedure CheckInteger(Var EdBox : TEdit);
Var
    I, Code : Integer;
Begin
    { Get text from TEdit control }
    Val(EdBox.Text, I, Code);

    { Error during conversion to Integer? }
    If Code<>0 Then
    Begin
        I:=0;
        MessageDlg('Please check your input details ?', mtError, [mbOk], 0);
        EdBox.Text := '0';
        { Get focus back to edit box }
        EdBox.SetFocus;
    End Else
        { Pass the integer value to edit box }
        EdBox.Text := IntToStr(I);
End;

Now you can call above procedure in Edit component OnExit event.

procedure TForm1.Edit1Exit(Sender: TObject);
begin
    CheckInteger(Edit1);
end;

Download This Delphi Tutorials.

Download materials for this article (Delphi - Tutorials)

Download - Check-validation-for-input-integer.zipCheck-validation-for-input-integer.zip
       File size: 7 KB, File type: zip
       Total downloads: 523, Upload date: February 02 - 2009

Nuuts :: June 04-2009 :: 04:34 AM

The validation procedure is very often demanding one ...
Thanks

tranzistor :: March 17-2010 :: 07:47 AM

This is an old mehod

use

try
    IntValue := strtoint(Edit1.Text);
  except
    ShowMessage('Please check your input details!');
    exit;
end;

Leave a comment