控制输入数字和小数点且保留一位小数位数的参考代码(对于右键复制粘贴请楼主自己想办法搞定):
procedure TMainForm.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
with TEdit(Sender) do
if (not ((key ='0') or (key='1') or (key ='2') or (key = '3')
or (key = '4') or (key = '5') or (key = '6') or (key = '7') or
(key = '8') or (key = '9') or (key = '.') or (key = #8)))
or ((key = '.') and (StringUtils.pos('.',Text) <> 0))
or ((key <> #8) and (StringUtils.pos('.',Text) <> 0)
and (selstart + 1 > StringUtils.pos('.',Text))
and (length(Text) - StringUtils.pos('.',text) = 1)) then
key := #0;
end; |