Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   OOP (https://www.clubdelphi.com/foros/forumdisplay.php?f=5)
-   -   LabeledEdit.onEnter <-- ayuda (https://www.clubdelphi.com/foros/showthread.php?t=32158)

Dr.Bizarre 27-05-2006 21:45:49

LabeledEdit.onEnter <-- ayuda
 
al terminar de tipear caracteres en un TEdit o en TLabeledEdit, quiero presionar enter y llame a un procedimiento:

Código Delphi [-]
procedure TForm1.cambio(Sender: TObject);
begin

  a:=StrToInt(LabeledEdit1.Text);
  Label1.Caption:=IntToStr(a);
  LabeledEdit1.Text:='';
  LabeledEdit1.Visible:=false;
  LabeledEdit2.Visible:=true;
  
end;

cuando lo cargo en el evento OnEnter del TLabeledEdit , todo parece que lo cargara en el OnActivate de la forma.

alguna sugerencia ?

marcoszorrilla 27-05-2006 21:59:15

Suponiendo que utilices un Tedit, pon el código pertinente en el evento OnKeyDown:

Código Delphi [-]
procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
   if key = 13 then
   showMessage('Pulsó Enter');
end;

De todas maneras te recomiendo en las conversiones utilizar un:
Código Delphi [-]
Try
a:=StrToInt(LabeledEdit1.Text);
Except
ShowMessage('Formato de número incorrecto.');
end;
Ya que pueden teclear algún caracter no apto para ser convertido y te arrojaría una excepción.

Un Saludo.

DarKraZY 31-05-2006 18:54:37

Hola marcoszorrilla,

¿Qué tal si en lugar de poder provocar una excepción, utilizase la función "TryStrToInt"?

Código Delphi [-]
var
  a: Integer;
begin
  if not TryStrToInt(LabeledEdit1.Text, a) then
    ShowMessage('Formato de número incorrecto.');


La franja horaria es GMT +2. Ahora son las 22:16:55.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi