1.如何通过程序检验在Edit中输入的字符是纯数字,还是字符?
解决方案 »
- 【贺岁第三枪】好汉歌 坛子2010贺岁版
- sql数据库导入导出
- 关于读卡器,急!在线等待。。。
- 当我使用一个临时变量的时候,DELPHI总是检测出说我这个变量没有用
- 如何赋当前日期给label.caption
- 紧急:一个启动窗口调用Delphi6通用密码DLL出错的问题!!!!!
- 请问各位大吓61.174.136.65 是哪个地区的ip
- query控件的requrstlive属性为true时的问题,
- 把四行C++原代码翻译为Delphi代码;指向数组的指针。请务必注意概念的准确性;欢迎大家的光临;
- 关于watch list窗口和evaluate/modify对话框
- 刷新怎么做啊?
- dbgrid的问题,大家都来看看
S: string;
F: Extended;
begin
S := '1211.22f';
if not TextToFloat(PChar(S), F, fvExtended) then
Showmessage('"' + s + '"不是数字!');
end;
S: string;
F: Extended;
begin
S := edit1.text;
if not TextToFloat(PChar(S), F, fvExtended) then
Showmessage('"' + s + '"不是数字!');
end;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DBCtrls, DB, ExtCtrls, Grids, DBGrids, DBTables, StdCtrls;type
TForm1 = class(TForm)
Edit1: TEdit;
procedure FormCreate(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
procedure KillRigthButton(var Msg: TMsg; var Handled: Boolean);
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
begin
application.OnMessage := KillRigthButton;
end;procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
//允许输入float值
if not (Key in ['0'..'9',chr(VK_BACK), chr(VK_LEFT),chr(VK_RIGHT),
chr(VK_TAB),chr(46)]) Then Key:=#0;
if (key=chr(46)) and (pos('.',(sender as TEdit).Text)>0) then Key:=#0;
//加入这句可以限制输入的位数
if (Length(Trim((sender as TEdit).Text))>=15) and (Key<>chr(VK_BACK)) then Key:=#0;
end;procedure TForm1.KillRigthButton(var Msg: TMsg; var Handled: Boolean);
begin
//防止右键弹出复制对话框
if Msg.hwnd = edit1.Handle then
if Msg.message = wm_rbuttonup then
Handled := true;
end;end.
s: String;
i: Integer;
begin
edit1.text:='sdfkj32230'
s := edit.text;
if (TryStrToInt(s, i) = True) then
ShowMessage(s + '是数字。')
else
ShowMessage(s + '不是数字。');
end;