procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); begin If (Key in [‘\‘, ‘/‘, ‘:‘, ‘*‘, ‘?‘, ‘<‘, ‘>‘, ‘|‘]) then Key := #0; Ifnot(Key in [‘0‘ .. ‘9‘, ‘a‘ .. ‘z‘, ‘A‘ .. ‘Z‘]) then Key := #0; end;
只能数字且只能输入一个小数点
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin ifnot(Key in [‘0‘ .. ‘9‘, ‘.‘, #8]) then Key := #0; if (Key = ‘.‘) and (Pos(‘.‘, Edit1.Text) > 0) then Key := #0; // 只能数字且只能输入一个小数点 end;
//只允许输入数字的TEdit组件
procedure TForm1.FormCreate(Sender: TObject); var wl:Integer; begin wl:=GetWindowLong(Edit1.Handle, GWL_STYLE); SetWindowLong(Edit1.Handle, GWL_STYLE, wl or ES_NUMBER); end;