Ver Mensaje Individual
  #4  
Antiguo 07-02-2013
Avatar de nlsgarcia
[nlsgarcia] nlsgarcia is offline
Miembro Premium
 
Registrado: feb 2007
Ubicación: Caracas, Venezuela
Posts: 2.206
Reputación: 21
nlsgarcia Tiene un aura espectacularnlsgarcia Tiene un aura espectacular
CarlosAlberto,

Cita:
Empezado por CarlosAlberto
¿cómo debo hacer para escribir sólo números en un "edit"?
Revisa este código:
Código Delphi [-]
procedure TForm1.CheckNumberKey(Sender: TObject; var Key: Char);
begin

   If (Length(Edit1.Text) = 0) and (Key = ',') then
   begin
      Key := Chr(0);
      exit;
   end;

   if (Pos(',',Edit1.Text) <> 0) and (Key = ',') then
   begin
      Key := Chr(0);
      exit;
   end;

   // Solo permite ingresar caracteres númericos, coma y tecla de retroceso
   If not (Key in ['0'..'9',',',#8]) then Key := Chr(0);

end;
El código anterior solo permite ingresar caracteres numéricos, coma decimal y tecla de retroceso en un control TEdit por medio del evento OnKeyPress.

Espero sea útil

Nelson.

Última edición por nlsgarcia fecha: 07-02-2013 a las 19:06:35.
Responder Con Cita