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 >
Wrap
Pascal/Delphi Source File
|
1999-01-24
|
3KB
|
106 lines
{##############################################################################
# Name: TWatchLabel - A label that displays the time and/or date #
# Author: Adrian Roberto Barbosa #
# Created: 19/01/1999 #
# UpDated: 23/01/1999 #
# Version: 1.0 #
# Description: A TLabel object that displays the system's date and/or #
# time. It uses a Timer inside to provide functionality. #
# You can choose which to display. #
# Revisions: 1.0 beta Date: 23/01/1999 #
# Delphi: Delphi 2 (tested) or later (developed in Delphi 4) #
# Copyright: None!!! It's free, so comments are welcome... #
# Contact: adrianrb@netsite.com.br OR adrianrb@base.com.br #
##############################################################################}
unit WLabel;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
type
TWatchLabel = class(TLabel)
private
{ Private declarations }
Timer: TTimer;
fShowTime: Boolean;
fShowDate: Boolean;
protected
{ Protected declarations }
procedure AtTime(Sender: TObject);
procedure SetShowTime(Value: Boolean);
procedure SetShowDate(Value: Boolean);
public
{ Public declarations }
constructor Create(AOwner: TComponent);override;
destructor Destroy;
published
{ Published declarations }
property ShowTime: Boolean read fShowTime write SetShowTime;
property ShowDate: Boolean read fShowDate write SetShowDate;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [TWatchLabel]);
end;
constructor TWatchLabel.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
fShowDate := False;
fShowTime := True;
Timer := TTimer.Create(Self);
Timer.Interval := 1000;
Timer.Enabled := True;
Timer.OnTimer := AtTime;
end;
destructor TWatchLabel.Destroy;
begin
Timer.Free;
end;
procedure TWatchLabel.SetShowTime(Value: Boolean);
begin
if Value <> fShowTime then
fShowTime := Value;
end;
procedure TWatchLabel.SetShowDate(Value: Boolean);
begin
if Value <> fShowDate then
fShowDate := Value;
end;
procedure TWatchLabel.AtTime(Sender: TObject);
var D,T: String;
begin
D := DateToStr(Now);
T := TimeToStr(Now);
if fShowTime then
Caption := T;
if fShowDate then
Caption := D;
if fShowDate and fShowTime then
Caption := D + ' ' + T;
if not(fShowDate) and not(fShowTime) then
begin
Caption := '>>>>> ERROR! <<<<<';
Timer.Enabled := False;
ShowMessage('Error. You must set at most one property!');
SetShowTime(True);
Timer.Enabled := True;
end;
end;
end.