KeyPress中写if not (Key in [0..9, #8]) and (Length(Edit1.Text) >= 4) then Key := #0试一下
SetWindowLong(Edit1.Handle, GWL_STYLE, GetWindowLong(Edit1.Handle, GWL_STYLE) or ES_NUMBER);
if not (key in ['0'..'9',#8,#13]) and (Length(Edit1.Text) >= 4) then begin key := #0; end;
还有一种限制长度方法就是把 Edit1 的 Maxlength属性设置为4
把一楼的改一下 if not (Key in ['0'..'9',#8]) then Key := #0;再加上yalaso(你啥时候来的?) 的方法,测试通过。
function CheckInt(Data : String) : Boolean; var code : Integer; r :Integer; begin Val(Data,r,code); if code = 0 then Result := True else Result := False; end;
GetWindowLong(Edit1.Handle, GWL_STYLE) or
ES_NUMBER);
begin
key := #0;
end;
if not (Key in ['0'..'9',#8]) then Key := #0;再加上yalaso(你啥时候来的?) 的方法,测试通过。
var
code : Integer;
r :Integer;
begin
Val(Data,r,code);
if code = 0 then
Result := True
else
Result := False;
end;