Zegar
Cel

Chcemy uzyskać efekt, aby w komponencie label był wyświetlony aktualny czas.



Potrzebne komponenty :

Nazwa

Klasa

Timer1

TTimer

Label1

TLabel



Metoda

1) Wstawiamy komponenty, wypisane w powyższej tabeli i zmieniamy im właściwość name na taką jaka jest w kolumnie "Nazwa"

2) Sprawdzamy, czy komponent Timer1 ma właściwość Enabled ustawioną na True, oraz czy właściwość Interval równa się 1000

3) Do obsługi zdarzenia OnTimer wpisujemy poniższy kod:

Label1.Caption := TimeToStr(Time); //kod pobiera z systemy aktalną godzinę  


4) Uruchamiamy program.

Kod źródłowy

unit Unit1;   interface   uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls;   type TForm1 = class(TForm) Timer1: TTimer; Label1: TLabel; procedure Timer1Timer(Sender: TObject); private { Private declarations } public { Public declarations } end;   var Form1: TForm1;   implementation   {$R *.DFM}   procedure TForm1.Timer1Timer(Sender: TObject); begin Label1.Caption := TimeToStr(Time); end;   end.


Autorem tekstu jest: Michał Siudziński
http://cpw.net.pl
Materiał dodany przez użytkownika: alphan