Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   OOP (https://www.clubdelphi.com/foros/forumdisplay.php?f=5)
-   -   Duda con el intervalo del timer (https://www.clubdelphi.com/foros/showthread.php?t=83112)

darkmaster360 12-05-2013 22:23:43

Duda con el intervalo del timer
 
Buenas, estaba intentando cambiar el invervalo del timer fuera del modo de prueba y quisiera hacerlo con el elemento Edit y UpDown, así para que para darle arriba disminuya el intervalo y para abajo aumente.

ecfisa 12-05-2013 22:36:42

Hola darkmaster360.

Por favor, cuando dudes en que foro debe ir tu mensaje no utilices Delphi/web utiliza el foro Varios, luego algún moderador se encargará de direccionarlo donde corresponda, muchas gracias.

Código Delphi [-]
...
implementation

const
   INCREMENTO = 100; // aquí el valor que quieras darle al incremento

procedure TForm1.FormCreate(Sender: TObject);
begin
  KeyPreview := True;
end;

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
  ti: Integer;
begin
  ti := Timer1.Interval;
  with Timer1 do
    case Key of
      VK_UP  : if ti < MaxInt then Inc(ti, INCREMENTO);
      VK_DOWN: if ti-INCREMENTO > 0 then Dec(ti, INCREMENTO);
    end;
  Timer1.Interval := ti;
end;
...

Saludos. :)

darkmaster360 12-05-2013 23:12:51

Lo siento ecfisa, lo tendré en cuenta.

Yo me refería al elemento Edit, donde al escribir un número fuese el intervalo del timer, y que el número se cambie con el elemento UpDown, no me refería al teclado me refería al elemento.

Saludos :)

ecfisa 12-05-2013 23:44:09

Hola Darkmaster360.

A... entiendo, pero ya hay un componente que realiza esa tarea el TSpinEdit (Pestaña Samples).

Un ejemplo:
Código Delphi [-]
...
implementation

var
  Cont : Integer = 0;

procedure TForm1.FormCreate(Sender: TObject);
begin
  SpinEdit1.MinValue := 1;
  SpinEdit1.MaxValue := MaxInt;
  SpinEdit1.Value    := Timer1.Interval;
end;

procedure TForm1.SpinEdit1Change(Sender: TObject);
begin
  Timer1.Interval := SpinEdit1.Value;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Caption := IntToStr(Cont);
  Inc(Cont);
end;
Revisa en la ayuda de Delphi sobre las propiedades del componente SpinEdit.

Saludos.:)

darkmaster360 13-05-2013 16:46:06

Hola ecfisa.

El código me funciono muchas gracias, lo único que no sabía el nombre de ese complemento.

Saludos :)


La franja horaria es GMT +2. Ahora son las 19:19:02.

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