Thanks for the tip.  Better than that, how about removing the variable
altogether:

procedure TForm1.Edit1Change(Sender: TObject);
begin
If Pos('.',Edit1.Text) > 0 then
If Length(Edit1.text) - Pos('.',Edit1.Text)> 1 then
Begin
Showmessage('Only one decimal point precision allowed');
Edit1.text := Copy(edit1.text,1,Length(Edit1.text)-1);
end;

BTW, This code does not prevent users to enter non-numeric code.

Tom Nesler

-----Original Message-----
From: [email protected] [mailto:[email protected]] On
Behalf Of Doug Chamberlin

Nesler, Thomas J wrote:
> How about this solution.  Use the Onchange Event to put this  code in:
> 
> procedure TForm1.Edit1Change(Sender: TObject);
> begin
> If Pos('.',Edit1.Text) > 0 then DotVar := True   //Global Var to check
> for decimal point
>                            else DotVar := False;
> If DotVar = true then  {check  for more than one number past decimal
> point}
>    If Length(Edit1.text) - Pos('.',Edit1.Text)> 1 then  
>       Begin
>         Showmessage('Only one decimal point precision allowed');
>         Edit1.text := Copy(edit1.text,1,Length(Edit1.text)-1);
>       end;
> end;
> 
> Be sure to create a global Boolean variable called DotVar to hold the
> flag for checking the number of decimals.

Why do you need to global variable at all if you are setting its value 
every time you enter the Edit1Change method?

BTW, I would set it using a single line:
   DotVar := (Pos('.',Edit1.Text) > 0);
_______________________________________________
Delphi mailing list -> [email protected]
http://lists.elists.org/cgi-bin/mailman/listinfo/delphi

Reply via email to