TTimer/fi
English · Français · Suomi · Русский
TTimer
on komponentti, joka Se löytyy komponenttipaletin Standard-välilehdeltä. Se tuo ajastimen, jonka tarkkuus voidaan esittää millisekuntteina. Se perii suurimman osan ominaisuuksistaan TCustomTimer:ltä.
Lähtölaskentaesimerkki.
- Pudota label, shape ja timer komponentit päälomakkeelle (TForm)
- Kaksoisklikkaa tätä Timer1-komponenttia lomakkeella (oletuskäsittelijä: OnTimer luodaan Timer1:lle, lähdekoodieditori avautuu).
- Lisää seuraava lähdekoodi tapahtumakäsittelijään:
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Label1.Caption := Format('%d sec',[start]);
Dec(start);
if (start < 5) then Shape1.Brush.Color:=clYellow;
if (start < 0) then begin
Timer1.Enabled := False;
Shape1.Brush.Color:=clGreen;
Label1.Caption := 'Finished!';
end;
end;- Luo lomakkeen Form1 OnCreate-tapahtumakäsittelijä (siirry komponenttimuokkaimen tapahtuman OnCreate-kohtaan ja klikkaa painiketta [...]).
- Täydennä lähdekoodi seuraavasti::
procedure TForm1.FormCreate(Sender: TObject);
begin
Caption := 'Countdown calculation';
Timer1.Interval := 1000;
Timer1.Enabled := True;
Label1.Caption := '';
Shape1.Shape := stCircle;
Shape1.Brush.Color:=clRed;
start := 20;
end;- Siirry lähdekoodieditorissa luokan (Class) TForm1 private osioon.
- Lisää sinne koodi:
start: integer; - Käynnistä program (painamalla näppäintä
F9)
Katso myös
From the Free Pascal wiki, page "TTimer/fi", as it stood on 2019-11-09 after a change by Djzepi, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.
Talk about this page
Nobody has opened a bench for this page yet. Sign in to open one.
