De C# a Lazarus Free Pascal lazarus / 73-Spanish ---------------------------------------------------------------------- RJH71 · 2019-10-25 08:20 Saludos amigos del foro, disculpen la molestia, yo estuve trabajando con C# cree una rutina para validaciones de datos, me podran ayudar como lo paso a Lasarus, soy principiante en esto: //Funcion Multiple para Validar si se Acepta un Entero, Decimal o Alfanumérico //Como se accesa: //e.Handled = !libreria.IsValidChar(e.KeyChar, libreria.ValueType.Entero); //e.Handled = !libreria.IsValidChar(e.KeyChar, libreria.ValueType.Decimal, txtPrecio.Text); //e.Handled = !libreria.IsValidChar(e.KeyChar, libreria.ValueType.Alfanumérico); public enum ValueType { Entero, Decimal, Alfanumérico } public static bool IsValidChar(char e, ValueType tipo, string texto = null) {    if (tipo == ValueType.Decimal) {       var decimalSeparator =       System.Threading.Thread.CurrentThread.CurrentCulture.NumberForma t.NumberDecimalSeparator;       return (char.IsDigit(e) || char.IsControl(e) || ((e.ToString() == decimalSeparator) && !texto.Contains(decimalSeparator)));    }    else if (tipo == ValueType.Entero {       return (char.IsDigit(e) || char.IsControl(e));    }    return true; } ---------------------------------------------------------------------- Edson · 2019-10-27 03:53 No manejo C# pero por el código que muestras, se puede ver que podrías fácilmente traducirlo, usando conjuntos. Para verificar si un caracter es un dígito, podrías usar algo como: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i if e in ['0'..'9'] then begin end; Así la sentencia: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i return (char.IsDigit(e) || char.IsControl(e)); podría traducirse como: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i exit( e in [#0..#31, '0'..'9']); Asumiendo que los caracteres de control son los código del 0 al 31. Ahora si trabajas en Unicode, habría que modificar un poco el código. ---------------------------------------------------------------------- RJH71 · 2019-10-27 15:34 Gracias por Responder Edson, me podrás ayudar por favor a armar un código, la verdad que soy novato en esto, estoy estudiando mediante videos tutoriales, gracias de antemano. ---------------------------------------------------------------------- lucamar · 2019-10-27 16:38 Ahí va una "unidad" completa que implementa la función equivalente en Pascal: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit CharTest; interface  type  TValueType = (vtEntero, vtDecimal, vtAlfanumerico);  function IsValidChar(e: char; tipo: TValueType; texto: String = ''): Boolean; implementation uses sysutils; function IsControl(e: char): Boolean;begin  Result := e in [#0..#31];end; function IsDigit(e: char): Boolean;begin  Result := e in ['0'..'9'];end; function IsValidChar(e: char; tipo: TValueType; texto: String = ''): Boolean;var   DecSep: Char;begin  DecSep := DefaultFormatSettings.DecimalSeparator;  case tipo of  vtEntero: Result := IsDigit(e) or IsControl(e);  vtDecimal: Result :=  (IsDigit(e) or IsControl(e) or                         ((e = DecSep) and                          not texto.Contains(DecSep));  else Result := True;  end;end; end; No la he testado pero no debería haber errores serios. Deberías tomarte un poco de tiempo para ver las correspondencias (¡y las diferencias!). ---------------------------------------------------------------------- RJH71 · 2019-10-28 14:02 Gracias por responder Lucamar, lo voy a revisar ok gracias y te aviso. ---------------------------------------------------------------------- RJH71 · 2019-10-28 14:57 Lucamar disculpa, en el KeyPressed pongo así: procedure TForm1.EdtPrecioKeyPress(Sender: TObject; var Key: char); begin    IsValidChar(Key, vtDecimal, EdtPrecio.Text); end; no se como va por eso te escribo, quedo de ti... ---------------------------------------------------------------------- RJH71 · 2019-10-28 15:13 En C# pongo asi: private void txtPrecio_KeyPress(object sender, KeyPressEventArgs e) {      e.Handled = !libreria.IsValidChar(e.KeyChar, libreria.ValueType.Decimal, txtPrecio.Text); } ---------------------------------------------------------------------- lucamar · 2019-10-28 17:39 No hay equivalente in Pascal para ese evento salvo que interceptes el mensaje directamente, que es lo que parece que hace (más o menos) C# Si lo que quieres es validar cada pulsación usa el evento OnKeyDown or OnKeyUp. Algo así como esto: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.EdtPrecioKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);begin  if not IsValidChar(Key, vtDecimal, EdtPrecio.Text) then    Key := 0;end; Lo que ese código provoca es que EdtPrecio ignore cualquier caracter no válido para un "precio". No es exactamente lo mismo (creo) que en C# pero basta para validar la pulsación de tecla. Date cuenta de que el código anterior es sólo un ejemplo, muy poco robusto. Por ejemplo, también interceptará (¡y dará por válidos!) "Shift+1", "Alt+2", etc. ---------------------------------------------------------------------- RJH71 · 2019-10-31 04:52 Gracias Lucamar funciona a la perfección, gracias!