今天你HAPPY了吗????????????????????我没有!!!!!!!!!!!!!!!!遇到问题了

tcl7819 2003-05-30 08:23:53
怎样让EDIT控件只能输入数字
解决了这个就Happy了
...全文
55 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
myfine 2003-06-01
  • 打赏
  • 举报
回复
用maskedit也可以
zleeway 2003-05-31
  • 打赏
  • 举报
回复
你解决了没有?给点分让我Happy吧.
nico_0823 2003-05-31
  • 打赏
  • 举报
回复
来晚了。。。
chenfeng3000 2003-05-30
  • 打赏
  • 举报
回复
呵呵,以前的贴子阿!
belllab 2003-05-30
  • 打赏
  • 举报
回复
Try
StrToInt(Edit1.Text);
Except
MessageBox(self.Handle,'请输入正确的数字!','错误',MB_ICONERROR);
Exit;
End;
jacky_shen 2003-05-30
  • 打赏
  • 举报
回复
SetWindowLong(Edit1.Handle, GWL_STYLE,GetWindowLong(Edit1.Handle, GWL_STYLE) or ES_NUMBER);
sean2000 2003-05-30
  • 打赏
  • 举报
回复
//过滤掉字符串中的非整型字符
function GetInteger(strInteger : string):string;
var
I, Code: Integer;
strTemp : string;
begin
strTemp := trim(strInteger);
Val(strTemp, I, Code);
if Code <> 0 then begin
strTemp := copy(strTemp,1,Code-1) + copy(strTemp,Code+1,length(strTemp)-Code);
end;
Result := strTemp;
end;

procedure TForm1.Edit1Change(Sender: TObject);
begin
Edit1.Text := GetInteger(Edit1.Text);
end;
lion_lh 2003-05-30
  • 打赏
  • 举报
回复
onkeypress

if (Key=#27) or (Key=#8) then exit;
if not (Key in ['0'..'9','+','-'] ) then Key:=#0;
whitetiger8 2003-05-30
  • 打赏
  • 举报
回复
用VAL函数,在检查EDIT时,可以VAL(edit1.text,a,b);其中A是返回的值,B是错误的值,如果B是0,说明输入全为数字,B为1,2,。。。各代表不同意义,你自己试试。不过这个方法只能输入整数,小数不是非常好用。还有一种方法是可以输入小数的。
try
strtofloat(edit1.text)
except
showmessage('只能输数字');
edit1.setfouse;
exit;
end
linzhisong(無聊) 的方法麻烦一点
goldencity 2003-05-30
  • 打赏
  • 举报
回复
if key not in['0','1','2','3','4','5','6','7','8','9'] then
begin
key:=#0 ;
end;
things 2003-05-30
  • 打赏
  • 举报
回复
KeyPress事件
if not (key in ['0'..'9', #8, #27, #13]) then //Tab键, 回退键, 回车键
begin
key := #0;
Exit;
end;

如果需要输入小数,请参考一下 linzhisong(無聊) 的回复
飞天林 2003-05-30
  • 打赏
  • 举报
回复
在exit事件
try
strtofloat(edit1.text)
except
edit1.setfouse;
exit;
end
linzhisong 2003-05-30
  • 打赏
  • 举报
回复
在keypress里写!
linzhisong 2003-05-30
  • 打赏
  • 举报
回复
if not (key in ['0'..'9',#8],'.') then
begin
if (key='.') and (pos('.',Tedit(sender).Text)=0) then exit;
key:=#0;
showmessage('必须填入数字!');
end;
v
outer2000 2003-05-30
  • 打赏
  • 举报
回复
use samples spinedit

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧