home *** CD-ROM | disk | FTP | other *** search
/ Chip 1999 March / Chip_1999-03_cd.bin / zkuste / delphi / D234 / AR_COMPS.ZIP / WLabel.pas < prev    next >
Pascal/Delphi Source File  |  1999-01-24  |  3KB  |  106 lines

  1. {##############################################################################
  2.  # Name:           TWatchLabel - A label that displays the time and/or date   #
  3.  # Author:         Adrian Roberto Barbosa                                     #
  4.  # Created:        19/01/1999                                                 #
  5.  # UpDated:        23/01/1999                                                 #
  6.  # Version:        1.0                                                        #
  7.  # Description:    A TLabel object that displays the system's date and/or     #
  8.  #                 time. It uses a Timer inside to provide functionality.     #
  9.  #                 You can choose which to display.                           #
  10.  # Revisions:      1.0 beta                                 Date: 23/01/1999  #
  11.  # Delphi:         Delphi 2 (tested) or later (developed in Delphi 4)         #
  12.  # Copyright:      None!!! It's free, so comments are welcome...              #
  13.  # Contact:        adrianrb@netsite.com.br OR adrianrb@base.com.br            #
  14.  ##############################################################################}
  15.  
  16. unit WLabel; 
  17.  
  18. interface
  19.  
  20. uses
  21.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  22.   StdCtrls, ExtCtrls;
  23.  
  24. type
  25.   TWatchLabel = class(TLabel)
  26.   private
  27.     { Private declarations }
  28.     Timer: TTimer;
  29.     fShowTime: Boolean;
  30.     fShowDate: Boolean;
  31.   protected
  32.     { Protected declarations }
  33.     procedure AtTime(Sender: TObject);
  34.     procedure SetShowTime(Value: Boolean);
  35.     procedure SetShowDate(Value: Boolean);
  36.   public
  37.     { Public declarations }
  38.     constructor Create(AOwner: TComponent);override;
  39.     destructor Destroy;
  40.   published
  41.     { Published declarations }
  42.     property ShowTime: Boolean read fShowTime write SetShowTime;
  43.     property ShowDate: Boolean read fShowDate write SetShowDate;
  44.   end;
  45.  
  46. procedure Register;
  47.  
  48. implementation
  49.  
  50. procedure Register;
  51. begin
  52.   RegisterComponents('Samples', [TWatchLabel]);
  53. end;
  54.  
  55. constructor TWatchLabel.Create(AOwner: TComponent);
  56. begin
  57.   inherited Create(AOwner);
  58.   fShowDate := False;
  59.   fShowTime := True;
  60.   Timer := TTimer.Create(Self);
  61.   Timer.Interval := 1000;
  62.   Timer.Enabled := True;
  63.   Timer.OnTimer := AtTime;
  64. end;
  65.  
  66. destructor TWatchLabel.Destroy;
  67. begin
  68.   Timer.Free;
  69. end;
  70.  
  71. procedure TWatchLabel.SetShowTime(Value: Boolean);
  72. begin
  73.   if Value <> fShowTime then
  74.     fShowTime := Value;
  75. end;
  76.  
  77. procedure TWatchLabel.SetShowDate(Value: Boolean);
  78. begin
  79.   if Value <> fShowDate then
  80.     fShowDate := Value;
  81. end;
  82.  
  83.  
  84. procedure TWatchLabel.AtTime(Sender: TObject);
  85. var D,T: String;
  86. begin
  87.   D := DateToStr(Now);
  88.   T := TimeToStr(Now);
  89.   if fShowTime then
  90.     Caption := T;
  91.   if fShowDate then
  92.     Caption := D;
  93.   if fShowDate and fShowTime then
  94.     Caption := D + '    ' + T;
  95.   if not(fShowDate) and not(fShowTime) then
  96.     begin
  97.       Caption := '>>>>> ERROR! <<<<<';
  98.     Timer.Enabled := False;
  99.       ShowMessage('Error. You must set at most one property!');
  100.       SetShowTime(True);
  101.       Timer.Enabled := True;
  102.     end;
  103. end;
  104.  
  105. end.
  106.