home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Programming Unleashed
/
Delphi_Programming_Unleashed_SAMS_Publishing_1995.iso
/
units
/
clock.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1995-03-20
|
3KB
|
153 lines
unit Clock;
{ Program copyright (c) 1995 by Charles Calvert }
{ Project Name: CLOCK3 }
interface
uses
SysUtils, WinTypes, WinProcs,
Messages, Classes, Graphics,
Controls, Forms, StdCtrls,
DsgnIntf, Dialogs;
type
TClock = class(TCustomControl)
private
FTimer: Integer;
FRunning: Boolean;
procedure SetRunning(Run: Boolean);
protected
procedure Paint; override;
procedure WMTimer(var Message: TMessage); message WM_Timer;
procedure WMDestroy(var Message: TMessage); message wm_Destroy;
public
constructor Create(AOwner: TComponent); override;
published
property Running: Boolean read FRunning write SetRunning;
end;
TClockEditor = class(TComponentEditor)
procedure Edit; override;
end;
TColorClock = class(TClock)
private
FColor: TColor;
procedure SetColor(Color: TColor);
protected
procedure Paint; override;
public
constructor Create(AOwner: TComponent); override;
published
property Color: TColor read FColor write SetColor;
end;
TColorNameProperty = class(TColorProperty)
public
function GetAttributes: TPropertyAttributes; override;
procedure Edit; override;
end;
procedure Register;
implementation
uses
StrBox;
procedure Register;
begin
RegisterComponents('Unleash', [TClock, TColorClock]);
RegisterComponentEditor(TClock, TClockEditor);
RegisterPropertyEditor(TypeInfo(TColor),
TClock, 'Color',
TColorNameProperty);
end;
{ --- TClock --- }
constructor TClock.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Width := 100;
height := 100;
FTimer := 1;
end;
procedure TClock.wmDestroy(var Message: TMessage);
begin
KillTimer(Handle, FTimer);
FTimer := 0;
inherited;
end;
procedure TClock.Paint;
begin
Canvas.Ellipse(0, 0, 100, 100);
end;
procedure TClock.SetRunning(Run: Boolean);
begin
if Run then begin
SetTimer(Handle, FTimer, 50, nil);
FRunning := True;
end else begin
KillTimer(Handle, FTimer);
FRunning := False;
end;
end;
procedure TClock.WMTimer(var Message: TMessage);
begin
Canvas.TextOut(10, 40, GetTimeString);
end;
{ --- TColorClock --- }
constructor TColorClock.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FColor := clGreen;
end;
procedure TColorClock.Paint;
begin
Canvas.Brush.Color := FColor;
inherited Paint;
end;
procedure TColorClock.SetColor(Color: TColor);
begin
FColor := Color;
InvalidateRect(Handle, nil, True);
end;
{ --- TClockEditor --- }
procedure TClockEditor.Edit;
begin
MessageDlg('Clock copyright (c) 1995 Charlie Calvert',
mtInformation, [mbOK],0);
end;
{ --- TColorNameProperty --- }
function TColorNameProperty.GetAttributes;
begin
Result := [paMultiSelect, paValueList, paDialog];
end;
procedure TColorNameProperty.Edit;
var
S: String;
begin
S := '';
InputQuery('New Color', 'Enter Color', S);
SetValue(S);
end;
end.