onexit事件中写 var f: integer; begin try f:=strtoint(edit1.text); if (f<100000) or (f>999999) then raise excption.create('out of range'); except application.messagebox('reinpout!','error',mb_ok); edit1.setfocus; end; end
设置edit1的MaxLength为6 在OnKeyPress事件中添加以下代码: if not( key in ['0'..'9',#8])then key:=#0;
设置edit1的MaxLength为6 在Edit1的OnKeyPress事件中添加以下代码: if not( key in ['0'..'9'])then key:=#0;
把edit的maxlength设置为6,且在onkeypress事件中写入如下代码: if (not(key in ['0'..'9'])and(key<>#45)) then key :=#0; 可以解决负数的。
Left = 160
Top = 80
Width = 120
Height = 21
EditMask = '000000;1;_'
MaxLength = 6
TabOrder = 0
Text = ' '
end
if Length(Edit1.Text) > 6 then
Key :=#0;
在OnKeyPress事件中添加以下代码:
if not( key in ['0'..'9',#27,#13,#8])then
key:=#0;
或者用MaskEdit代替Edit。
edit1.maxlength:=6;还可以用label1.Caption :=inttostr(length(edit1.Text))得到他的个数
再if一下不就可以了吗
数字就可以用assci码来定了
var
f: integer;
begin
try
f:=strtoint(edit1.text);
if (f<100000) or (f>999999) then raise excption.create('out of range');
except
application.messagebox('reinpout!','error',mb_ok);
edit1.setfocus;
end;
end
在OnKeyPress事件中添加以下代码:
if not( key in ['0'..'9',#8])then
key:=#0;
在Edit1的OnKeyPress事件中添加以下代码:
if not( key in ['0'..'9'])then
key:=#0;
if (not(key in ['0'..'9'])and(key<>#45)) then
key :=#0;
可以解决负数的。