procedure
CheckReal(Var EdBox : TEdit);
Var
R
: Real;
Code
: Integer;
Begin
{
Get text from TEdit control }
Val(EdBox.Text,
R, Code);
{
Val - Converts a string to a numeric representation. }
{
Error during conversion to Real? }
If
Code<>0 Then
Begin
R:=0;
MessageDlg('Please
check your input details ?', mtError, [mbOk], 0);
EdBox.Text
:= '0.00';
{
Get focus back to edit box }
EdBox.SetFocus;
End
Else
{
Pass formatted (with two decimal places) real value to text box
}
EdBox.Text
:= Format('%f', [R]);
{
Format - Returns a formatted string assembled from a format
string and an array of arguments. }
End;
Now
you can call above procedure in Edit component OnExit event.
procedure
TForm1.Edit1Exit(Sender: TObject);
begin
CheckReal(Edit1);
end;