现在想输入时以特定的字符或数字为头。如:只能以1开头的数字,10001、10002

解决方案 »

  1.   

    在KEYPRESS事件里写
    i:=copy(edit1.text,1,1);
    if i<>'1' then
       key:=0;
    end;
      

  2.   

    在KEYPRESS事件里写
    var
      s:string;
    begin
      s:= edit1.Text;
      if (trim(s)='')and(key <> '1')then
        key:= #0;
    end;
      

  3.   

    就这样了
    关于tedit输入得一些用法
    只能输入数字
    OnKeyPress事件中
    begin
      if not (Key in ['0'..'9']) and (ord(Key)<>8) then
        Key:=#0;
    end;在onkeydown事件中写if key=vk_return then
    begin
      try
        StrToInt(Edit1.text);
      except
        Edit1.clear;
      end;
    end;
    SetWindowLong(Edit1.Handle, GWL_STYLE,GetWindowLong(Edit1.Handle, GWL_STYLE) or   ES_NUMBER);procedure Tbook.Edit1KeyPress(Sender: TObject; var Key: Char);
    begin
       if not (key in['0'..'9',#8,#13]) then 如果愿意还可以加上#13
         begin
         key:=#0;
         MessageBeep(1);
         application.MessageBox('请输入数字类型的!','提示',mb_iconquestion);
         end;
    end;