Ver Mensaje Individual
  #20  
Antiguo 07-07-2007
gabrielkc gabrielkc is offline
Miembro
 
Registrado: jun 2007
Ubicación: Chihuahua Mexico
Posts: 118
Reputación: 17
gabrielkc Va por buen camino
Código Delphi [-]
function EsNumero(cValue: string):Boolean;
var i,Estado:Byte;
begin
 if Length(cValue)>0 then
  Estado:=1
 else
  Estado:=0;
 i:=1;
 while (i<=Length(cValue))and(Estado<>0) do
  begin
    case Estado of
     1:case cValue[i] of
        '0'..'9':Estado:=2;
        '-':Estado:=3;
        else Estado:=0;
       end;
     2:case cValue[i] of
        '0'..'9':Estado:=2;
       '.':Estado:=4;
       '-':Estado:=0;
        else Estado:=0;
       end;
     3:case cValue[i] of
       '0'..'9':Estado:=2;
        else Estado:=0;
       end;
     4:case cValue[i] of
        '0'..'9':Estado:=5;
        else Estado:=0;
       end;
     5:case cValue[i] of
        '0'..'9':Estado:=5;
        else Estado:=0;
       end;
    end;
   Inc(i)
  end;
 Result:=(Estado in [2,5])
end;
Con un Autómata

Código Delphi [-]
procedure TForm1.Button1Click(Sender: TObject);
begin
 if EsNumero(edit1.Text) then
  ShowMessage('si')
 else
  ShowMessage('no')
end;
Así se llamaría, si no me equivoco...... funciona en todos los casos.
Responder Con Cita