如何控制EDIT中输入的数值在0~59之间?

解决方案 »

  1.   

    在KeyPress事件和KeyChange事件中控件?
      

  2.   

    if ( not (Key in ['0'..'59'])) then
    begin
    //your code
    end;
      

  3.   

    ?!
    我倒Key in ['0'..'59'])),有这样的?
    首先用SetWindowLong(Edit1.Handle, GWL_STYLE,
                      GetWindowLong(Edit1.Handle, GWL_STYLE) or
                      ES_NUMBER);    
    限制edit只能输入数字
    然后在change事件中判断
    if edit.text<>'' and strtoint(edit1.text)>=0 and strtoint(edit1.text)<=59 then
       .........
      

  4.   

    Key in ['0'..'59']))
    高手,呵呵
      

  5.   

    procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
    begin   if Not (Key In [#8, #48 .. #57]) then Key := #0;
       if Length(Edit1.Text) > 2 then Key := #0;
       if StrToIntDef(Edit1.Text + Key, 0) > 59 then Edit1.Text := '';end;
      

  6.   

    所谓智者千虑,hammer_shi兄不必如此:)
    看来真的是晚上了,一下冒了好多星星出来
      

  7.   

    onchange事件中来来进行判断就是了~
      

  8.   

    我想可以在ONEXIT事件中判断,使用VAL函数,或其他方法限制(如try strtoint(s) > 0 and...  except end;)。
      

  9.   

    Edit1.MaxLength:=2;procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
    begin
      if not (Key in ['0'..'9',#8]) then Key:=#0;
    end;procedure TForm1.Edit1Exit(Sender: TObject);
    var
      num,rflag:Integer;
    begin
      Val(Edit1.Text,num,rflag);
      if num>59 then num:=59;
      Edit1.Text:=IntToStr(num);
    end;