请问如何限制一个输入数字的长度?

sillyer 2002-05-10 10:32:50
比如说我要的数据为7位其中包括两位小数。谢谢。
...全文
72 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
ly_liuyang 2002-05-10
  • 打赏
  • 举报
回复
use tmaskedit, DIY也可以,上面的方法已经可以了
ihihonline 2002-05-10
  • 打赏
  • 举报
回复
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
var
I: Integer;
begin
if ( key in ['0'..'9','.',#13,#8,#46]) then
begin
if (Key = #8) and (Key = '.' ) then
J := J - 1;
if Key = '.' then
begin
for I := 0 to Length(Edit1.Text ) - 1 do
begin
if Copy(Edit1.Text ,I , 1) ='.' then
J := J +1 ;
if J >= 2 then
Key := #0;
end;
if (Length(Edit1.Text) = 0) or (Length(Edit1.Text) = 6) then
Key := #0;
end else
Exit;
end else
Key := #0;
end;

var
Form1: TForm1;
J : Integer;
implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
edit1.MaxLength :=7;
J :=0;
end;
macro_love 2002-05-10
  • 打赏
  • 举报
回复
以上程序写在edit1的keypress事件中
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if not (key in ['0'..'9',#8,#46]) then
key:=#0
else if length(edit1.Text)>=7 then
key:=#0
end;
macro_love 2002-05-10
  • 打赏
  • 举报
回复
if not (key in ['0'..'9',#8,#46]) then
key:=#0
else if length(edit1.Text)>=7 then
key:=#0
ihihonline 2002-05-10
  • 打赏
  • 举报
回复
你等一下,我给你做一个;
cookieyfeng 2002-05-10
  • 打赏
  • 举报
回复
同意楼上所说,用maskedit控件
haishen 2002-05-10
  • 打赏
  • 举报
回复
说的不清楚,你是要限制什么的输入长度,
比如:Edit,那只要设Maxlength就可以了
或者你问的是别的什么东西,说清楚点好不好
  • 打赏
  • 举报
回复
可以试一下maskedit控件。很方便的。
祝:身体健康!!

5,388

社区成员

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

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