使用 SetWindowLong(Edit1.Handle, GWL_STYLE, GetWindowLong(Edit1.Handle, GWL_STYLE) or ES_NUMBER); 使edit只能输入数字,无需判断
上面的程序会在IDE环境下报错的。也可以通过键值判断procedure TFrom1.edt1Press(Sender: TObject; var Key: Char); begin if not ((key >= '0') and (key <= '9')) then if ((key <> '.') and (key <> #8)) or ((key = '.') and (pos('.', Trim(edt1.text)) > 0)) then key := #0; end;
编译产生错误!
SetWindowLong(Edit1.Handle, GWL_STYLE,
GetWindowLong(Edit1.Handle, GWL_STYLE) or
ES_NUMBER); 使edit只能输入数字,无需判断
begin
if not ((key >= '0') and (key <= '9')) then
if ((key <> '.') and (key <> #8)) or
((key = '.') and (pos('.', Trim(edt1.text)) > 0)) then
key := #0;
end;
你的方法太棒.可我不会api,你可否详悉些?谢谢!
strtoint(edit1.text);
except
showmessage('数据转换错误!');
abort;
end;