我是这样写的
//过滤键盘按键信息
procedure THupEdit.KeyPress(var Key: Char);
begin
inherited KeyPress(Key);
if FEnterTab and (Key = #13) then
begin
PostMessage(Handle, WM_KEYDOWN, VK_TAB, 0);
Key := #0;
Exit;
end; case FInputStyle of
stInteger:
if not (Key in ['0'..'9', Chr(8)]) then Key := #0;
stFloat:
begin
if not (Key in ['0'..'9', '.', Chr(8)]) then Key := #0;
if (Key = '.') and (Pos(Key, Text) > 0) then Key := #0;
end;
stMoney:
begin
if not (Key in ['0'..'9', '.', Chr(8)]) then Key := #0;
if (Key = '.') and (Pos(Key, Text) > 0) then Key := #0;
if (Pos('.', Text) > 0) and (Key <> Chr(8)) and
((Length(Text) - Pos('.', Text)) >= 2) then Key := #0;
end;
stBkdh:
begin
if pos('-',Trim(TEdit(THupedit).Text))>0 then //此处是错误的,只 是 想告诉你个思想
if not (Key in ['0'..'9', Chr(8)]) then Key := #0 else
if not (Key in ['0'..'9', '-', Chr(8)]) then Key := #0;
end;
end;
end;
//过滤键盘按键信息
procedure THupEdit.KeyPress(var Key: Char);
begin
inherited KeyPress(Key);
if FEnterTab and (Key = #13) then
begin
PostMessage(Handle, WM_KEYDOWN, VK_TAB, 0);
Key := #0;
Exit;
end; case FInputStyle of
stInteger:
if not (Key in ['0'..'9', Chr(8)]) then Key := #0;
stFloat:
begin
if not (Key in ['0'..'9', '.', Chr(8)]) then Key := #0;
if (Key = '.') and (Pos(Key, Text) > 0) then Key := #0;
end;
stMoney:
begin
if not (Key in ['0'..'9', '.', Chr(8)]) then Key := #0;
if (Key = '.') and (Pos(Key, Text) > 0) then Key := #0;
if (Pos('.', Text) > 0) and (Key <> Chr(8)) and
((Length(Text) - Pos('.', Text)) >= 2) then Key := #0;
end;
stBkdh:
begin
if pos('-',Trim(TEdit(THupedit).Text))>0 then //此处是错误的,只 是 想告诉你个思想
if not (Key in ['0'..'9', Chr(8)]) then Key := #0 else
if not (Key in ['0'..'9', '-', Chr(8)]) then Key := #0;
end;
end;
end;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货