Fórum limitar valor digitado em um edit #531359
11/09/2015
0
como faço pra limitar o valor digitado em um edit
hoje eu utilizo esse código
procedure TFrmCadastro_Usuario.Edit4KeyPress(Sender: TObject; var Key: Char);
begin
if key =#13 then Edit1.SetFocus;
if CharInSet (key, ['A'..'Z','a'..'z','0','8','9']) then
begin
key := #0;
end;
end;
eu preciso na verdade que ele filtre e permita apenas 1, 2, 3, 4, 5, 6, 7 . da forma como está valores como 11, 12, 55... a combinação entre eles passa e eu n quero isso
Emanuel Gonçalves
Curtir tópico
+ 0Posts
11/09/2015
Raimundo Pereira
Você pode usar um spinedit;
valuemin =1
valuemax=10
Mesmo se a pessoa digitar 55 ou 11 ou 12.
No exit o próprio componete seta o valor para o valor maximo.
if SpinEdit1.Value>SpinEdit1.MaxValue then
begin
SpinEdit1.Clear;
end;
Gostei + 0
11/09/2015
Emanuel Gonçalves
Você pode usar um spinedit;
valuemin =1
valuemax=10
Mesmo se a pessoa digitar 55 ou 11 ou 12.
No exit o próprio componete seta o valor para o valor maximo.
if SpinEdit1.Value>SpinEdit1.MaxValue then
begin
SpinEdit1.Clear;
end;
P2
optei em fazer o teste no botão de gravar
procedure TFrmCadastro_Usuario.BtnCadastrarUsuarioClick(Sender: TObject);
begin
valormin := 1;
valormax := 7;
FDQuery1.Insert;
FDQuery1LOGIN.Value:= Edit1.Text;
FDQuery1SENHA.Value:= Edit2.Text;
FDQuery1CONF_SENHA.Value:= Edit3.Text;
if ((SpinEdit1.value < valormin) or (SpinEdit1.Value > valormax)) then
ShowMessage('Valor invalido!')
else
FDQuery1COD_GRUPO.Value:= (SpinEdit1.Value);
FDQuery1.post;
Edit1.Clear;
Edit2.Clear;
Edit3.Clear;
Edit4.Clear;
end;
vlw deu certo
Gostei + 0
11/09/2015
Emanuel Gonçalves
Você pode usar um spinedit;
valuemin =1
valuemax=10
Mesmo se a pessoa digitar 55 ou 11 ou 12.
No exit o próprio componete seta o valor para o valor maximo.
if SpinEdit1.Value>SpinEdit1.MaxValue then
begin
SpinEdit1.Clear;
end;
P2
optei em fazer o teste no botão de gravar
procedure TFrmCadastro_Usuario.BtnCadastrarUsuarioClick(Sender: TObject);
begin
valormin := 1;
valormax := 7;
FDQuery1.Insert;
FDQuery1LOGIN.Value:= Edit1.Text;
FDQuery1SENHA.Value:= Edit2.Text;
FDQuery1CONF_SENHA.Value:= Edit3.Text;
if ((SpinEdit1.value < valormin) or (SpinEdit1.Value > valormax)) then
ShowMessage('Valor invalido!')
else
FDQuery1COD_GRUPO.Value:= (SpinEdit1.Value);
FDQuery1.post;
Edit1.Clear;
Edit2.Clear;
Edit3.Clear;
Edit4.Clear;
end;
vlw deu certo
pensei melhor e coloquei o teste no evento onexit do spinedit
procedure TFrmCadastro_Usuario.SpinEdit1Exit(Sender: TObject);
begin
valormin := 1;
valormax := 7;
if ((SpinEdit1.value < valormin) or (SpinEdit1.Value > valormax)) then
begin
ShowMessage('Valor invalido!');
SpinEdit1.SetFocus;
end
end;
tento em vista que é um campo obrigatório para cadastrar usuário , assim o botão cadastrar se encarrega apenas de gravar
Gostei + 0
11/09/2015
Lucas Ramos
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if (key <> #8) then
begin
if not(Key in ['0'..'9']) then
Key := #0;
end;
end;
procedure TForm1.Edit1Exit(Sender: TObject);
begin
if (Edit1.Text <> '') then
begin
if (StrToInt(Edit1.Text) < 1) or (StrToInt(Edit1.Text) > 7) then
begin
ShowMessage('Valor tem que estar entre 1 e 7');
Edit1.SetFocus;
end;
end;
end;
Gostei + 0
11/09/2015
Emanuel Gonçalves
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if (key <> #8) then
begin
if not(Key in ['0'..'9']) then
Key := #0;
end;
end;
procedure TForm1.Edit1Exit(Sender: TObject);
begin
if (Edit1.Text <> '') then
begin
if (StrToInt(Edit1.Text) < 1) or (StrToInt(Edit1.Text) > 7) then
begin
ShowMessage('Valor tem que estar entre 1 e 7');
Edit1.SetFocus;
end;
end;
end;
gostei da dica, valeu !!!!
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)