Recent

Author Topic: using timer to set form colour  (Read 3682 times)

durbslaw

  • Newbie
  • Posts: 1
using timer to set form colour
« on: September 21, 2017, 03:22:27 pm »
Hi Forum,

I am new to Lazarus and Delphi, I am trying to set the form color by using the Timer, in other words I would like the form color to change 3 different colors in the first 3 seconds.
the pseudo code I have is;

procedure TForm1.Timer1Timer(Sender: TObject);
var interval : Integer;
begin
  interval:=Timer1.ComponentIndex;
  case  interval of
  1 :  Form1.Color:=clred;
  2 :  Form1.Color:=clBlue;
  3 :  Form1.Color:=clGreen;
end;

end;
end. 

of course I could be completely lost...any help would be appreciated.

Regards

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: using timer to set form colour
« Reply #1 on: September 21, 2017, 04:24:04 pm »
the code you posted makes no sense what makes you thing that the componentIndex property changes value?
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: using timer to set form colour
« Reply #2 on: September 21, 2017, 04:33:17 pm »
If you don't need the timer after this then of course you can FREE it...

Code: Pascal  [Select][+][-]
  1. Unit Unit1;
  2. {$MODE OBJFPC}{$H+}{$J-}
  3.  
  4. Interface
  5.  USES
  6.   Classes,  SysUtils,
  7.   Forms,    Controls,
  8.   Graphics, ExtCtrls;
  9.  
  10.  TYPE
  11.   TForm1 = Class(TForm)
  12.    Procedure FormCreate       (Sender: TObject);
  13.    Procedure TimerChangeColor (Sender: TObject);
  14.  
  15.     PRIVATE
  16.      iCount: Integer;
  17.   End;
  18.  
  19.  VAR
  20.   Form1: TForm1;
  21.  
  22. Implementation
  23. {$R *.LFM}
  24.  
  25.  
  26. Procedure TForm1.FormCreate(Sender: TObject);
  27.   Var
  28.    tiColorChange: TTimer;
  29.  Begin
  30.   Color := clRed;
  31.   iCount:= 0;
  32.  
  33.   tiColorChange         := TTimer.Create(Self);
  34.   tiColorChange.Interval:= 1000;
  35.   tiColorChange.OnTimer := @TimerChangeColor;
  36.   tiColorChange.Enabled := True;
  37.  End;
  38.  
  39.  
  40. Procedure TForm1.TimerChangeColor(Sender: TObject);
  41.  Begin
  42.   Inc(iCount);
  43.  
  44.   Case iCount
  45.   Of
  46.    1: Color:= clBlue;
  47.    2: Begin
  48.        Color:= clGreen;
  49.        TTimer(Sender).Enabled:= False;
  50.       End;
  51.   End;
  52.  End;
  53.  
  54. END.
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

jamie

  • Hero Member
  • *****
  • Posts: 6077
Re: using timer to set form colour
« Reply #3 on: September 22, 2017, 01:45:03 am »
In the timer event..

 Tag := (Tag + 1) and 3;
 Case Tag of
    0:Form1.color := ?
    1:Form1.color := ?
    2:Form1.color := ?
    3:Form1.Color := ?
 End;
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018