怎样在EDIT的ONPRESSKEY中编程实现只允许输入数字型数据!能把详细代码列出吗?谢谢!
解决方案 »
- 求助:MDI主窗体无法打开子窗体!
- 第一次写数据时老是出现EOleexception,实际上数据提交成功,以后都正常。
- 怎么重新设置一个外部程序的窗口标题和屏蔽一些菜单相啊?
- Borland销售生产线,REAL公司将免费发放产品
- socket问题,同时连接的用户数量??
- 救教:如何实现PC通过串口发送文件(如MP3)到手机中
- 请问用spcomm控件如何发送integer数组,另外^表示什么意思?
- 如何调用API的SHELL外壳属性?
- 神呀,救救我吧!(关于多表关联的设计问题)
- 初级问题,如何在DBGRID中添加诸如CHECKBOX,COMBOBOX之类的控件?
- 请各位DELPHI高手留下QQ,方便联系与讨论!
- 刚刚接触多层数据库开发,我高手请教几个问题,请进来看看!
begin
if not (key in ['0'..'9','.',#8,#13]) then
key := #0;
end;
begin
if (Key<'0') or (Key>'9') then
Key:=chr(0);
end;
begin
if not (key in ['0'..'9','.',#8,#13]) then
abort;
end;
if (Key<'0') and (Key>'9') and (Key<>'-') and (Key<>'.') then Key:= #0;
if( (Key='-') and ( (Length(TEdit(Sender).Text)>0) ))then Key:=#0;
if((Key='.') and ( (Length(TEdit(Sender).Text)>0) and ( Pos(TEdit(Sender).Text,'.')>0) )) then Key:=#0;
2.禁止输入全角字符
If (Key=#163) then
Begin
Key:=#0;
showmessage('不能输入全角字符,将输入法改为半角');
end;
If (Key=#161) then
Begin
Key:=#0;
end;
If (Key=#170) then
Begin
Key:=#0;
end;
3.函数实现
Function PLstrtoInt(ss:string):Int64;
var
plst,pls,plss,plsss:string;
NOdian,NOjianhao,NOjiahao:boolean;
plf:Int64;
i:integer;
begin
plss:='';
NOdian:=true;
NOjianhao:=true;
NOjiahao:=true; pls:=trim(ss);
for i:=1 to length(pls) do
begin
plst:=copy(pls,i,1);
if (plst='0') or (plst='1') or (plst='2') or
(plst='3') or (plst='4') or (plst='5') or
(plst='6') or (plst='7') or (plst='8') or
(plst='9') or
((plst='.') and Nodian) or
((plst='+') and Nojiahao) or
((plst='-') and Nojianhao)
then plss:=plss+plst;
if (plst='.') then Nodian :=false;
if (plst='+') then Nojiahao :=false;
if (plst='-') then Nojianhao :=false;
end;
Plsss:=copy(plss,1,1);
plst:='';
if (length(plss)>=2) then
begin
for i:=2 to length(plss) do
Begin
plst:=copy(plss,i,1);
if (plst<>'+') and (plst<>'-') then plsss:=plsss+plst;
End;
plf:=strtoInt(plsss);
end
else
begin
if (plss='-') Or (plss='+') Or (plss='') then plf:=0
else plf:=strtoInt(plss);
end;
result:=plf;
end;
4.生成可以为SQL用的语句
Function PLstrtoNotFuHao(ss:string):String;
var
pls:string;
begin
pls:=trim(ss);
while Pos(' ', plS) > 0 do
plS[Pos(' ', plS)] := '0';
while Pos('''', plS) > 0 do
plS[Pos('''', plS)] := '0';
while Pos(':', plS) > 0 do
plS[Pos(':', plS)] := '0';
while Pos(';', plS) > 0 do
plS[Pos(';', plS)] := '0';
while Pos('"', plS) > 0 do
plS[Pos('"', plS)] := '0';
result:=pls;
end;