一个个地在KeyPress事件中写if not (key in ['0'..'9', '.']) then Key:=#0;太麻烦了......
解决方案 »
- 急.delphi7支持mapxtreme2005吗???
- 如何分割这条Update语句??
- 使用wiseinstallation打包delphi7.0的bde程序,出现如下错误提示:指定了不正确的bde版本,请确定,本机当前配置bde的版本是5.0.1.22或更
- 小弟问个简单的问题,在线等待!
- 欢迎访问一个很好的网站www.5ierp.com
- 自定义公式问题?
- 我要学DEPHI 高手推荐几本好书啊
- 1000分求解,如何用ClientDataSet.SaveToFile保存数据集的UpdateStatus属性
- 如何建立一个动态连接库.dll,菜鸟发问
- 用delphi5自带的报表如何自动转换页面格式,也就是动态的根据字段的多少改变。
- 高手请教`~
- 请问,我用idftp下载一个文件后,需要自己校验文件吗?
var
i,m_Length:Integer;
begin
Result := false;
m_Length := Length(s);
if m_Length <= 0 then
begin
Exit;
end;
for i:= 1 to m_Length do
begin
if (i = 1) then
begin
if (not( s[i] in ['0'..'9'])) and (not (s[i] = '-')) then
begin
Exit;
end;
end
else
begin
if not( s[i] in ['0'..'9']) then
begin
Exit;
end;
end;
end;
Result := true;
end;
然后再你的每个edit 中调用这个函数,添加判断就好了!这样简单些!
同时也赞成,一楼的看法,就是在一个edit中添加一段代码,然后让所有edit keydown事件只想着一个公共模块。
希望对楼主有所帮助!如果感觉还有什么困难,就给我发邮件:
[email protected]
SysUtils, Classes, Controls, StdCtrls, Windows;type
TNumEdit = class(TEdit)
private
{ Private declarations }
protected
procedure CreateParams(var Params: TCreateParams); override;
{ Protected declarations }
public
constructor Create(Owner: TComponent); override;
{ Public declarations }
published
{ Published declarations }
end;procedure Register;implementationprocedure Register;
begin
RegisterComponents('Standard', [TNumEdit]);
end;procedure TNumEdit.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.Style := Params.Style or ES_NUMBER or ES_CENTER;
end;constructor TNumEdit.Create(Owner: TComponent);
begin
inherited;
Text := '0';
end;