if combobox1.Text='编号' then
begin
adoquery1.SQL.Clear;
adoquery1.Close;
adoquery1.SQL.Text:='select * from db_name where id='+edit1.Text+'';
adoquery1.Open;
请问上面那个代码,当combobox1.text='编号' 时我想让 edit1这个文本框只能输入数字,请问用什么办法能实现。

解决方案 »

  1.   

    procedure TForm1.FormCreate(Sender: TObject);
    begin
    SetWindowLong(Edit1.Handle,  GWL_STYLE,
                                       GetWindowLong(Edit1.Handle,  GWL_STYLE)  or
                                       ES_NUMBER);
    end;
      

  2.   

    在EDIT的OnKeyPress事件中if (key=#13) and (combobox1.text='编号') then
      if not (key in ['0'..'9']) then key:=#0;
      

  3.   

    在combobox1的keypress写:
    if (combobox1.Text='编号') and ((key <'0') or (key > '9')) and (key <> #8) then
          key := #0;
      

  4.   

    在EDIT1的KEYDOWN和KEYUP过程中判断