在ONKEYPRESS里写下 procedure Tform1.Edit1KeyPress(Sender: TObject; var Key: Char); begin if key>'9' or key<'0' then abort end;
在OnKeydown事件中,判断键值是否为数字,就可以了,
还要有括弧 procedure Tform1.Edit1KeyPress(Sender: TObject; var Key: Char); begin if (key>'9') or (key<'0') then abort end;
procedure TSellForm.NumEditKeyPress(Sender: TObject; var Key: Char); begin if key in ['0'..'9'] then else Key:=#0; end;
procedure TQueryBilForm.ComPTextKeyPress(Sender: TObject; var Key: Char); begin if Assigned(CurField) then begin if (CurField.DataType in [ftFloat,ftCurrency,ftBCD]) then begin if not((key in ['0'..'9','.','-',#8])) then begin key := #0 end else begin if (Key='.') and (Pos('.',TEdit(Sender).Text)<>0) then Key:=#0 else if (Key='-') and (Pos('-',TEdit(Sender).Text)<>0) then Key:=#0; end; end else if (CurField.DataType in [ftAutoInc,ftSmallint, ftInteger, ftWord, ftBytes,ftLargeint]) then begin if not ((Key in ['0'..'9','-',#8])) then begin Key:=#0 end else begin if(Key='-') and (Pos('-',TEdit(Sender).Text)<>0) then Key:=#0; end; end else Exit; end; end;
procedure Tform1.Edit1KeyPress(Sender: TObject; var Key: Char); begin if not (key in ['0'..'9',#8]) then begin key:=#0; ShowMessage('您输入的并非有效数字!'); end end;
上面很多都写错了 if not(Key in ['0'..'9']) then Key := #0;要加括号哈~~~我喜欢风焱的那种,so cool~~~
在edit1 keypress事件中加入以下代码即可:procedure TForm1.edit1KeyPress(Sender: TObject; var Key: Char); begin if not (key in ['0'..'9','.',#13,#8]) then key:=#0; if (key = '.') and (Pos('.', edit1.text) > 0) then key:= #0; end;还有,各位大虾关注一下我的帖子好吗 http://expert.csdn.net/Expert/topic/1842/1842061.xml?temp=9.022158E-02
procedure Tform1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if key>'9' or key<'0' then abort
end;
procedure Tform1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if (key>'9') or (key<'0') then abort
end;
begin
if key in ['0'..'9'] then
else
Key:=#0;
end;
begin
if Assigned(CurField) then
begin
if (CurField.DataType in [ftFloat,ftCurrency,ftBCD]) then
begin
if not((key in ['0'..'9','.','-',#8])) then
begin
key := #0
end
else
begin
if (Key='.') and (Pos('.',TEdit(Sender).Text)<>0) then
Key:=#0
else if
(Key='-') and (Pos('-',TEdit(Sender).Text)<>0) then
Key:=#0;
end;
end
else if (CurField.DataType in [ftAutoInc,ftSmallint, ftInteger, ftWord,
ftBytes,ftLargeint]) then
begin
if not ((Key in ['0'..'9','-',#8])) then
begin
Key:=#0
end
else
begin
if(Key='-') and (Pos('-',TEdit(Sender).Text)<>0) then
Key:=#0;
end;
end
else
Exit;
end;
end;
StrtoFloat(Edit1.Text);
except
messagebox(handle,'请输入数字!',mb_ok);
end;
具体可见delphi帮助文档!
begin
if not key in ['0'..'9'] then
Key := #0;
end;
SetWindowLong(Edit1.Handle, GWL_STYLE,
GetWindowLong(Edit1.Handle, GWL_STYLE) or
ES_NUMBER);
http://expert.csdn.net/Expert/topic/1793/1793502.xml?temp=.824093
begin
if not (key in ['0'..'9',#8]) then
begin
key:=#0;
ShowMessage('您输入的并非有效数字!');
end
end;
if not(Key in ['0'..'9']) then
Key := #0;要加括号哈~~~我喜欢风焱的那种,so cool~~~
回复人: lzmmail(李子) ( ) 信誉:99 2003-5-16 16:20:28 得分:0
在edit1 keypress事件中加入以下代码即可:procedure TForm1.edit1KeyPress(Sender: TObject; var Key: Char);
begin
if not (key in ['0'..'9','.',#13,#8]) then key:=#0;
if (key = '.') and (Pos('.', edit1.text) > 0) then key:= #0;
end;还有,各位大虾关注一下我的帖子好吗
http://expert.csdn.net/Expert/topic/1842/1842061.xml?temp=9.022158E-02