Budzik
Cel

Nasz program ma przypominać budzik. Po wpisaniu godziny program sprawdza czy jeszcze nie nadeszła. W przypadku jeśli taka sytuacja zaistniała wyświetla komunikat.



Potrzebne komponenty :

Nazwa

Klasa

Label1

TLabel

Label2

TLabel

Label3

TLabel

Edit1

TEdit

Edit2

TEdit

Edit3

TEdit



Metoda

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

2) Do obsługi funkcji OnTimer komponetu TTimer dodajemy kod:

var A, B, C : String; begin A := FormatDateTime('hh', Time); Label1.Caption := A; B := FormatDateTime('nn', Time); Label2.Caption := B; C := FormatDateTime('ss', Time); Label3.Caption := C;   if Edit3.Text <> '' then if Edit2.Text <> '' then if Edit1.Text <> '' then if Edit3.Text = C then begin if Edit2.Text = B then begin if Edit1.Text = A then begin MessageDlg('Nadeszła twoja godzina...', mtInformation , [mbOk], 0); end; end; end;


3) Klikamy w pustym miejscu formulaarza i z zakładki Event wybieramy funkcję OnActive. Dodajemy kod:

Label1.Caption := FormatDateTime('hh', Time); Label2.Caption := FormatDateTime('nn', Time); Label3.Caption := FormatDateTime('ss', Time);


4) Uruchamiamy program.

Kod źródłowy

unit Unit1;   interface   uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls;   type TForm1 = class(TForm) Label1: TLabel; Label2: TLabel; Label3: TLabel; Edit1: TEdit; Timer1: TTimer; Edit3: TEdit; Edit2: TEdit; procedure Timer1Timer(Sender: TObject); procedure FormActivate(Sender: TObject); private { Private declarations } public { Public declarations } end;   var Form1: TForm1;   implementation   {$R *.DFM}   procedure TForm1.Timer1Timer(Sender: TObject); var A, B, C : String; begin A := FormatDateTime('hh', Time); Label1.Caption := A; B := FormatDateTime('nn', Time); Label2.Caption := B; C := FormatDateTime('ss', Time); Label3.Caption := C;   if Edit3.Text <> '' then if Edit2.Text <> '' then if Edit1.Text <> '' then if Edit3.Text = C then begin if Edit2.Text = B then begin if Edit1.Text = A then begin MessageDlg('Nadeszła twoja godzina...', mtInformation , [mbOk], 0); end; end; end; end;   procedure TForm1.FormActivate(Sender: TObject); begin Label1.Caption := FormatDateTime('hh', Time); Label2.Caption := FormatDateTime('nn', Time); Label3.Caption := FormatDateTime('ss', Time); end;   end.


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