Edit的问题

chenzhechenge 2004-07-17 02:04:33
1.如何通过程序检验在Edit中输入的字符是纯数字,还是字符?
...全文
124 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
lionlsl 2004-07-17
  • 打赏
  • 举报
回复
kl2000() 做得非常好
chenzhechenge 2004-07-17
  • 打赏
  • 举报
回复
初学不懂嘛,请大家多多指教
gstang 2004-07-17
  • 打赏
  • 举报
回复
n>∞
sankis 2004-07-17
  • 打赏
  • 举报
回复
aibeyond2003(编程我一直用算盘) 有道理。
aibeyond2003 2004-07-17
  • 打赏
  • 举报
回复
这样的问题已经在这里问了N次了。n>100吧!
sankis 2004-07-17
  • 打赏
  • 举报
回复
这种问题怎么天天有人问啊?
jijl2001 2004-07-17
  • 打赏
  • 举报
回复
var
s: String;
i: Integer;
begin
edit1.text:='sdfkj32230'
s := edit.text;
if (TryStrToInt(s, i) = True) then
ShowMessage(s + '是数字。')
else
ShowMessage(s + '不是数字。');

end;
kl2000 2004-07-17
  • 打赏
  • 举报
回复
unit Unit1;

interface

uses
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.
飞天揽月 2004-07-17
  • 打赏
  • 举报
回复
var
S: string;
F: Extended;
begin
S := edit1.text;
if not TextToFloat(PChar(S), F, fvExtended) then
Showmessage('"' + s + '"不是数字!');
end;
飞天揽月 2004-07-17
  • 打赏
  • 举报
回复
var
S: string;
F: Extended;
begin
S := '1211.22f';
if not TextToFloat(PChar(S), F, fvExtended) then
Showmessage('"' + s + '"不是数字!');
end;

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧