同上~!~!

解决方案 »

  1.   

    if (key<#48) or (key>#57) then
      begin
        key := #0;
        showmessage('error');
      end;
      

  2.   

    在tedit的onkeypress事件写下下列代码:
    if (not (Key in ['0'..'9'])) and (key<>#8) then
         Key :=#0;
      

  3.   

    或者
    TRY
      STRTOFLOAT(EDIT1.TEXT)
    EXCEPT
      SHOWMESSAGE();
    END;
      

  4.   

    if key in[0..9] tehn
    或用MaskEdit
      

  5.   

    1.
    var
    i:double;
    begin
    try
     i:=strtofloat(youredit.text);
    except
     showmessage('error');
    end;
    2.在edit的onbuttonpress(好像是这么写的)事件中
    begin
    if not (key in ['0'..'9','.',#8]) then //0-9,小数点,和backspace以外的键
     key:=#0
    end;
    这个方法有问题,可以输入无数个小数点,可以自己写点东西来限制小数点的位置和个数
      

  6.   

    错了,真丢脸,是onkeypress,最近看书看傻了,5555555
      

  7.   

    //KeyPress里写:
    if not (Key in ['0'..'9', '.', #7, #8]) then 
    begin
      Key := #0;
      ShowMessage('只能输入数字!');
    end;
      

  8.   

    各位好象忘记了一个,就是可以Ctrl+V粘贴非数值,所以嘛————把OnExit事件也加上!OnExit事件就这样就可以:
    try
     i:=strtofloat(youredit.text);
    except
     showmessage('error'); //显示出错
     youredit.Text:='';
     youredit.SetFoucs; //设置焦点,要用户重输
    end;
      

  9.   

    procedure TForm.Edit1Change(Sender: TObject);
    begin
      try
        Edit1.Text:=FloatToStr(StrToFloat(Edit1.Text));
      except
        Showmessage('Error!');
      end;
    end;procedure Tchjsd.Edit4KeyPress(Sender: TObject; var Key: Char);
    begin
      if not (key in ['0'..'9',#8]) then
        begin
          key:=#0;
          Showmessage('Error');
        end;
    end;
      

  10.   

    //KeyPress里写:
    if not (Key in ['0'..'9', #8]) then 
    begin
      Key := #0;
      ShowMessage('只能输入数字!');
    end;
      

  11.   

    #8是BACKSPACE
    #13是ENTER
    其实就是这个键的键值,我也是菜鸟,我只知道这些了
    给你个小程序,你就知道其他的键的键值.
    也是在edit的onkeypress里写的
    begin
    label1.caption:=inttostr(ord(key));
    end;我懒得调试了,这句话应该没错吧 应该是这样, ^_^
      

  12.   

    有人在CSDN里贴过所有的键的,你搜索一下吧~在这里要学会搜索的,^_^
      

  13.   

    http://expert.csdn.net/Expert/topic/2541/2541694.xml?temp=.211529
    我至少看见6次了这个题目,没有一个完整的
    建议把这个题目放进精华区
    ---------------
    屏蔽Ctrl+V
    屏蔽鼠标右键菜单
    屏蔽非数字字符
    只允许输入一个 .
      

  14.   

    我写过在EDIT中只许出现一个合法的小数点位置的,但是用的办法是巨笨的,希望高手出来指点迷津,^_^
      

  15.   

    if key in ['0','1','2','3','4','5','6','7','8','9'] then
    else
    key:=#0;
      

  16.   

    TRY
      STRTOFLOAT(EDIT1.TEXT)
    EXCEPT
      SHOWMESSAGE();
      edit1.setfocus;
    END;
      

  17.   

    这是我自己以前用VB写的,考虑得很周全。只是可能逻辑有点混乱。
    Private Sub Text1_KeyPress(KeyAscii As Integer)
       If ((KeyAscii < Asc(0) Or KeyAscii > Asc(9)) And KeyAscii <> 46) And KeyAscii <> 8 Then
          KeyAscii = 0
       End If
       If KeyAscii = Asc(0) Then
          If Key_0 = False Then KeyAscii = 0
          
       End If
       If KeyAscii = 46 Then
          Select Case Key_D
          Case "前面加零"
             Text1.Text = "0."
             SendKeys "{end}"
             KeyAscii = 0
          Case "已经有了"
             KeyAscii = 0
          Case "不可再加", "不可加"
             KeyAscii = 0
          End Select
       End If
    End Sub
    Private Function Key_0() As Boolean
       If Len(Text1.Text) = 0 Then
          Key_0 = False
       Else
          Key_0 = True
       End If
       If Text1.SelText <> "" Then
          If InStr(1, Text1.Text, Text1.SelText) = 1 Then
             Key_0 = False
          End If
       End If
    End Function
    Private Function Key_D() As String
       Dim TempStr As String
       Dim TempI As Integer
       Dim TempI1 As Integer
       
       '文本框里面一无所有
       If Len(Text1.Text) = 0 Then
          Key_D = "前面加零"
          Exit Function
       End If
       
       If Text1.Text = Text1.SelText Then
          Key_D = "前面加零"
          Exit Function
       End If
       '文本框里面没有"."号
       TempI = InStr(1, Text1.Text, ".")
    '   MsgBox TempI
       If TempI <= 0 Then
          TempStr = Text1.SelText
          If TempStr <> "" Then               '文本框里面没有点号,但是选中了开头的数字。
             TempI1 = InStr(1, Text1.Text, TempStr)
             If TempI1 <= 1 Then
                Key_D = "不可加"
                Exit Function
             End If
          End If
          Exit Function
       End If
       
       '文本框里面已经有了,而且没有被选中的文本
       If TempI > 0 And Text1.SelText = "" Then
          Key_D = "已经有了"
          Exit Function
       End If
       
       '文本框里面有了,有被选中的文本。
       TempStr = Text1.SelText
    '   MsgBox TempStr
       If TempStr <> "" Then
          TempI1 = InStr(Text1.Text, TempStr)
     '     MsgBox TempI1
          If TempI1 <= 1 Then
             Key_D = "不可加"
             Exit Function
          End If
    '      TempI = InStr(1, Text1.Text, ".")
    '      If TempI <= 0 Then Exit Function
          
          
          
          TempI = InStr(1, TempStr, ".")
          If TempI > 0 Then Exit Function
          
          Key_D = "不可再加"
       End If
    End Function
      

  18.   

    不用ctrl+v啊,用右键菜单也可以粘贴啊 
     还要用粘帖的功能啦~!~!
    再贴一段代码,实现粘贴功能:procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    begin
    if (ssctrl in shift) and ((key=118) OR (key=86)) then
       edit1.PasteFromClipboard;
    end;
    是不是对的呀~!~!
      

  19.   

    在大多数情况下,设置Edit的OnChange更简便,不管拷贝还是键盘输入,一律要接受检查的。连OnKeyPress也不必设。
        procedure TForm1.Edit1Change(Sender: TObject);
    begin
    try StrtoFloat(edit1.Text)
    except
    messagebox(handle,'请检查输入数字!','出错警告',mb_iconwarning);
    end;
    end;