Hi Stephen,
> This code nearly works, but allows more than one decimal point
Try the following....
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
var
SeparatorPos: Integer;
begin
if Key in ['0'..'9'] then
begin
SeparatorPos := Pos('.', TEdit(Sender).Text);
if ((SeparatorPos > 0) and (Length(TEdit(Sender).Text) -
SeparatorPos > 0)) and (TEdit(Sender).SelLength = 0) then
Key := #0;
end
else
begin
if Key in [',', '.'] then
begin
if (Pos(',', TEdit(Sender).Text) > 0) or (Pos('.',
TEdit(Sender).Text) > 0) then
Key := #0
else
Key := DecimalSeparator;
end
else if (Key <> #8) then
Key := #0;
end;
end;
Regards,
Cord
StaffPlan
http://www.staffplan.co.uk
_______________________________________________
Delphi mailing list -> [email protected]
http://lists.elists.org/cgi-bin/mailman/listinfo/delphi