Chcemy uzyskać efekt, aby w komponencie label był wyświetlony aktualny czas.
Nazwa |
Klasa |
Timer1 |
TTimer |
Label1 |
TLabel |
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.
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.