Ver Mensaje Individual
  #1  
Antiguo 01-03-2024
darkamerico darkamerico is offline
Miembro
 
Registrado: dic 2010
Posts: 233
Reputación: 14
darkamerico Va por buen camino
Red face Mi rutina para validar ingreso de datos

Saludos amigos, aquí comparto mi rutina para validar de forma sencilla el ingreso de un conjunto personalizado de datos en un componente TEdit:

Código Delphi [-]
function TFunciones.ValidarEntrada(Key:char; tipoEntrada: string):char;
begin
  if tipoEntrada='SoloLetras' then
  begin
    if not (key in ['a'..'z','A'..'Z',' ', #7, #8, #13]) then Result := #0
    else Result:=key;
  end;
  if tipoEntrada='SoloNumerosEnteros' then
  begin
    if not (key in [#8,'0'..'9','+','-',#13]) then Result:=#0
    else Result:=key;
  end;
  if tipoEntrada='SoloNumerosDecimales' then
  begin
    if not (Key in ['0'..'9','.',#8]) then Result:=#0
    else Result:=key;
  end;
  if tipoEntrada='LetrasYNumeros' then
  begin
    if not (Key in ['0'..'9','.','a'..'z','A'..'Z',' ', #7, #8]) then Result:=#0
    else Result:=key;
  end;
end;

Uso:
Código Delphi [-]
procedure TfrmBuscaSuministro.txtBuscaSumKeyPress(Sender: TObject; var Key: Char);
begin
  key:=cls.ValidarEntrada(Key, 'SoloNumerosEnteros');
end;

Si hubieran mejores propuestas por favor agradecería las sugerencias.

Atte
Responder Con Cita