1.如何通过程序检验在Edit中输入的字符是纯数字,还是字符?

解决方案 »

  1.   

    var
      S: string;
      F: Extended;
    begin
      S := '1211.22f';
      if not TextToFloat(PChar(S), F, fvExtended) then
        Showmessage('"' + s + '"不是数字!');
    end;
      

  2.   

    var
      S: string;
      F: Extended;
    begin
      S := edit1.text;
      if not TextToFloat(PChar(S), F, fvExtended) then
        Showmessage('"' + s + '"不是数字!');
    end;
      

  3.   

    unit Unit1;interfaceuses
      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.
      

  4.   

    var
      s: String;
      i: Integer;
    begin
      edit1.text:='sdfkj32230'
      s := edit.text;
      if (TryStrToInt(s, i) = True) then
        ShowMessage(s + '是数字。')
      else
        ShowMessage(s + '不是数字。');
      
    end;
      

  5.   

    这样的问题已经在这里问了N次了。n>100吧!
      

  6.   

    aibeyond2003(编程我一直用算盘) 有道理。