Função que verifique se o edit somente tem números
Olá a todos!
Estou precisando de uma função que verifique se um Edit somente tem números digitados.
ATENÇÃO!
NÃO É PARA FORMATAR O CAMPO !!!
Eu quero somente uma função que me resulte TRUE ou FALSE se no Edit tem somente números digitados.
Estou tentando com esta função, segue:
Porém o [b:f28b1c745b]Delphi 2009[/b:f28b1c745b] me resulta estes erros, segue:
[color=red:f28b1c745b][DCC Warning] UnitVendas.pas(99): W1050 WideChar reduced to byte char in set expressions. Consider using ´CharInSet´ function in ´SysUtils´ unit.
[DCC Warning] UnitVendas.pas(108): W1035 Return value of function ´VerificaSomenteNumeros´ might be undefined[/color:f28b1c745b]
Podem me ajudar?
Estou precisando de uma função que verifique se um Edit somente tem números digitados.
ATENÇÃO!
NÃO É PARA FORMATAR O CAMPO !!!
Eu quero somente uma função que me resulte TRUE ou FALSE se no Edit tem somente números digitados.
Estou tentando com esta função, segue:
Function VerificaSomenteNumeros(Const Texto: String): Boolean; var Contador : Integer; begin For Contador := 1 to Length(Texto) do Begin If (Texto[Contador] in [´0´..´9´]) then Begin Result := True; end else Begin Result := False; end; end; end;
Porém o [b:f28b1c745b]Delphi 2009[/b:f28b1c745b] me resulta estes erros, segue:
[color=red:f28b1c745b][DCC Warning] UnitVendas.pas(99): W1050 WideChar reduced to byte char in set expressions. Consider using ´CharInSet´ function in ´SysUtils´ unit.
[DCC Warning] UnitVendas.pas(108): W1035 Return value of function ´VerificaSomenteNumeros´ might be undefined[/color:f28b1c745b]
Podem me ajudar?
Devmedia
Curtidas 0
Respostas
Luciano.lirio
24/11/2008
tenta essa.
function VerificaSomenteNumeros(Const Texto: String): Boolean; var Contador : Integer; begin Result := True; for Contador := 1 to Length(Texto) do if not (Texto[Contador] in [´0´..´9´]) then begin Result := False; Break; end end; procedure TForm1.Button1Click(Sender: TObject); begin if VerificaSomenteNumeros(Edit1.Text) then ShowMessage(´Tem somente números´) else ShowMessage(´Tem somente números´) end;
GOSTEI 0
Luciano.lirio
24/11/2008
function VerificaSomenteNumeros(Const Texto: String): Boolean; var Contador : Integer; begin Result := Length(Texto) > 0; for Contador := 1 to Length(Texto) do if not (Texto[Contador] in [´0´..´9´]) then begin Result := False; Break; end end; procedure TForm1.Button1Click(Sender: TObject); begin if VerificaSomenteNumeros(Edit1.Text) then ShowMessage(´Tem somente números´) else ShowMessage(´Não tem somente números´) end;
GOSTEI 0