Budzik
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 komponentu 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 formularza 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);
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.
5 komentarzy
A nie lepiej tak:
//... Jakiś kod ...
if Edit3.Text <> '' Then
if Edit2.Text <> '' Then
if Edit1.Text <> '' Then
if Edit3.Text = C Then //Bez begin
if Edit2.Text = B Then //Bez begin
if Edit1.Text = A Then Begin
//A tutaj jakieś PlaySound czy coś...
MessageBox(0, PChar('Budzik !'+#13+'Już jest '+Edit1.Text+':'+Edit2.Text+#13+'Zapomniałeś ?'), 'Budzik', MB_IconInformation);
Halt;
End;
//... Jakiś kod ...
Ten twój komunikat pojawiałby się do nieskończoności (do wyłączenia aplikacji ;-) )
Nie analizowałem dokładnie kodu, ponieważ jest średnio czytelny (dlatego mogłem też popełnić błąd)
ale mi budzik, wyskakuje se komunikat, to ja po pierwszych zajęciach w PeKiNie to umiałem, ale normal bajer
w książce 'ćwiczenia praktyczne z... Podstawowe komponenty delphi' chyba
majciejplonski, no fakt ale po kilku poradnikach delphi można większość kodów z Gotowców zrobić, choć są (kilka) na wyższym poziomie
PS trochę ten budzik mija się z celem, bo mi by się nie chciało mieć cały czas kompa włączonego