H
huangyanming
Unregistered / Unconfirmed
GUEST, unregistred user!
{ 此控件开发简单,只始用于初学者
小时钟组件 Version 1.0.0
by 黄延明 2004.01.12
简介:通过使用Active属性控制它的启停;
在Panel面板上显示时间,显示时间的格式由DateTimeFormat指出;
整点报时;
定时提示,用户输入定点时间,以及该时间的安排之后,到点自动提示,如何提示由用户定时,并可触发事件。
参数列表:Timer TTimer 用于定时的计时器
FActive Boolean 控制启停状态的变量
FUusy Boolean 构件报时忙标志
FBeep Boolean 是否报时标志
FInteval Integer 时钟刷新周期,单位为秒
Fcaption String Panel上输出的时间
FDateTimeFormat String 时间显示格式
FDateHints Tstrings 定时时间序列
FShowdateHint TNotifyEvent 定时提示内容的输出方法,由用户定义
FDateHint String 定时提示内容
FNow TDateTime 暂时锁存的时间值
使用方法:在定义定时提示时,可以调用DateHints.add()方法。格式如:DateHints.add('07:05:03|起床了');
注意事项:因':'号的中英文不同,所以定义了两个转化字符串为整数的函数
function stringtoint_char(value:string):integer;
function stringtoint_int(value:string):integer;
这也是本人花了两个小时才找出的错误;
E-mail:huangyanming007@eyou.com
QQ:18025085
}
{另外:因本人也正在学习当中,在开发组件时用到组件的"属性编辑器",但在delphi5以前版本中引用的DsgnIntf.pas
在delphi6/7中被拆分为另外几个单元,所以本在写组件用到"属性编辑器"时遇到困难,请哪们高手帮助写一段程序,
展示一下在delphi6/7中如何写这类属性编辑器!在此谢过!
E-mail:huangyanming007@eyou.com
QQ:18025085
}
unit clock;
interface
uses
sysutils,wintypes,winprocs,messages,classes,graphics,controls,forms,dialogs,extctrls,menus,StrUtils;
type
Tclock = class(TPanel)
private
Timer:TTimer;
FActive:Boolean;
FBusy:Boolean;
FBeep:Boolean;
FInterval:Integer;
FCaption:String;
FDateTimeFormat:String;
FDateHints:TStringS;
FShowdateHint:TNotifyEvent;
FDateHint:String;
FNow:TDateTime;
procedure WMSize(var message:TWMSize);message WM_SIZE;
procedure PanelMouseDown(sender:TObject; Button:TMouseButton; Shift:TShiftstate; X,Y:integer);
procedure CheckBeep;
procedure CheckdateHint;
procedure EnableTimer(value:Boolean);
procedure SetDateHints(value:TStrings);
function stringtoint_char(value:string):integer;
function stringtoint_int(value:string):integer;
protected
procedure TimeronTime(sender:TObject);
public
constructor create(AOwner:TComponent);override;
destructor destroy; override;
published
property Active:Boolean read Factive write EnableTimer default False;
property Beep: Boolean read FBeep write FBeep default True;
property Caption:String read Fcaption;
property DteTimeFormat:String read FDateTimeFormat write FDateTimeFormat;
property DateHints:Tstrings read FDateHints write SetDateHints;
property DateHint:string read FDateHint;
property Interval:Integer read FInterval Default 1;
property onShowDateHint:TNotifyEvent read FShowDateHint write FShowDateHint;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [Tclock]);
end;
constructor Tclock.Create(Aowner:TComponent);
begin
inherited Create(Aowner);
Parent:=AOWner As TWinControl;
TPanel(self).caption:='';
TPanel(self).onMouseDown:=panelMouseDown;
FActive:=False;
Timer:=TTimer.create(self);
Timer.interval:=1000;
Timer.Enabled:=FActive;
Timer.ontimer:=TimeronTime;
FDateTimeFormat:='hh: mm: ss';
FCaption:=FormatDateTime(FDateTimeFormat,now);
FInterval:=1;
FBeep:=True;
FDateHints:=TStringList.Create;
end;
destructor Tclock.destroy;
begin
Timer.Free;
FDateHints.Free;
inherited Destroy;
end;
function Tclock.stringtoint_char(value:string):integer;
begin
result:=3600*strtoint(copy(value,1,2))+60*strtoint(copy(value,5,2))+strtoint(copy(value,9,2));
end;
function Tclock.stringtoint_int(value:string):integer;
begin
result:=3600*strtoint(copy(value,1,2))+60*strtoint(copy(value,4,2))+strtoint(copy(value,7,2));
end;
Procedure Tclock.WMSize(var Message:TWMSize);
var w,h:integer;
begin
inherited;
w:=width;
h:=height;
if w<font.size*length(FDateTimeFormat) then
w:=font.size*length(FDateTimeFormat);
if h<font.size then
h:=font.Size;
if (w<>width) or (h<>height) then
inherited SetBounds(left,top,w,h);
message.Result:=0;
end;
procedure Tclock.PanelMouseDown(sender:TObject; Button:TMouseButton; Shift:TShiftstate; X,Y:integer);
begin
releasecapture;
perform(WM_SysCommand,$F012,0);
end;
procedure Tclock.TimeronTime(sender:TObject);
begin
FNow:=Now;
if FCaption<>FormatDateTime(FDateTimeFormat,FNow) then
begin
FCaption:=FormatDateTime(FDateTimeFormat,FNow);
Tpanel(self).Caption:=FCaption;
end;
if not FBusy then
begin
FBusy:=True;
try
CheckBeep;
CheckDateHint;
finally
FBusy:=False
end;
end;
end;
procedure Tclock.CheckBeep;
var h,m,s,ss:word;
begin
DecodeTime(FNow,h,m,s,ss);
if ((m=0)and (s=0)) or ((m=59)and (s>=60-h)) then
begin
if FBeep then
showmessage('整点报时');//可在此嵌入汇编,使计算机发声。
end;
end;
procedure Tclock.CheckdateHint;
var s,sdate,shint:string;
i:integer;
begin
for i:=0 to FDateHints.Count -1 do
begin
s:=FDateHints;
sDate:=Copy(s,1,pos('|',s)-1);
shint:=Copy(s,pos('|',s)+1,Length(s));
if stringtoint_char(FCaption)=stringtoint_int(sDate) then //如果比较两个字符串,始终没有相同情况,因为中英文中":"不同。
begin
FDateHint:=sHint; //可在此嵌入汇编,使计算机发声。
if assigned(FShowDateHint) then
FShowDateHint(self)
else
showmessage(shint);
end; end;
end;
procedure Tclock.SetDateHints(value:TStrings);
begin
FDateHints.Assign(value);
end;
procedure Tclock.EnableTimer(value:boolean);
begin
FActive:=value;
Timer.Enabled:=FActive;
end;
end.
小时钟组件 Version 1.0.0
by 黄延明 2004.01.12
简介:通过使用Active属性控制它的启停;
在Panel面板上显示时间,显示时间的格式由DateTimeFormat指出;
整点报时;
定时提示,用户输入定点时间,以及该时间的安排之后,到点自动提示,如何提示由用户定时,并可触发事件。
参数列表:Timer TTimer 用于定时的计时器
FActive Boolean 控制启停状态的变量
FUusy Boolean 构件报时忙标志
FBeep Boolean 是否报时标志
FInteval Integer 时钟刷新周期,单位为秒
Fcaption String Panel上输出的时间
FDateTimeFormat String 时间显示格式
FDateHints Tstrings 定时时间序列
FShowdateHint TNotifyEvent 定时提示内容的输出方法,由用户定义
FDateHint String 定时提示内容
FNow TDateTime 暂时锁存的时间值
使用方法:在定义定时提示时,可以调用DateHints.add()方法。格式如:DateHints.add('07:05:03|起床了');
注意事项:因':'号的中英文不同,所以定义了两个转化字符串为整数的函数
function stringtoint_char(value:string):integer;
function stringtoint_int(value:string):integer;
这也是本人花了两个小时才找出的错误;
E-mail:huangyanming007@eyou.com
QQ:18025085
}
{另外:因本人也正在学习当中,在开发组件时用到组件的"属性编辑器",但在delphi5以前版本中引用的DsgnIntf.pas
在delphi6/7中被拆分为另外几个单元,所以本在写组件用到"属性编辑器"时遇到困难,请哪们高手帮助写一段程序,
展示一下在delphi6/7中如何写这类属性编辑器!在此谢过!
E-mail:huangyanming007@eyou.com
QQ:18025085
}
unit clock;
interface
uses
sysutils,wintypes,winprocs,messages,classes,graphics,controls,forms,dialogs,extctrls,menus,StrUtils;
type
Tclock = class(TPanel)
private
Timer:TTimer;
FActive:Boolean;
FBusy:Boolean;
FBeep:Boolean;
FInterval:Integer;
FCaption:String;
FDateTimeFormat:String;
FDateHints:TStringS;
FShowdateHint:TNotifyEvent;
FDateHint:String;
FNow:TDateTime;
procedure WMSize(var message:TWMSize);message WM_SIZE;
procedure PanelMouseDown(sender:TObject; Button:TMouseButton; Shift:TShiftstate; X,Y:integer);
procedure CheckBeep;
procedure CheckdateHint;
procedure EnableTimer(value:Boolean);
procedure SetDateHints(value:TStrings);
function stringtoint_char(value:string):integer;
function stringtoint_int(value:string):integer;
protected
procedure TimeronTime(sender:TObject);
public
constructor create(AOwner:TComponent);override;
destructor destroy; override;
published
property Active:Boolean read Factive write EnableTimer default False;
property Beep: Boolean read FBeep write FBeep default True;
property Caption:String read Fcaption;
property DteTimeFormat:String read FDateTimeFormat write FDateTimeFormat;
property DateHints:Tstrings read FDateHints write SetDateHints;
property DateHint:string read FDateHint;
property Interval:Integer read FInterval Default 1;
property onShowDateHint:TNotifyEvent read FShowDateHint write FShowDateHint;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [Tclock]);
end;
constructor Tclock.Create(Aowner:TComponent);
begin
inherited Create(Aowner);
Parent:=AOWner As TWinControl;
TPanel(self).caption:='';
TPanel(self).onMouseDown:=panelMouseDown;
FActive:=False;
Timer:=TTimer.create(self);
Timer.interval:=1000;
Timer.Enabled:=FActive;
Timer.ontimer:=TimeronTime;
FDateTimeFormat:='hh: mm: ss';
FCaption:=FormatDateTime(FDateTimeFormat,now);
FInterval:=1;
FBeep:=True;
FDateHints:=TStringList.Create;
end;
destructor Tclock.destroy;
begin
Timer.Free;
FDateHints.Free;
inherited Destroy;
end;
function Tclock.stringtoint_char(value:string):integer;
begin
result:=3600*strtoint(copy(value,1,2))+60*strtoint(copy(value,5,2))+strtoint(copy(value,9,2));
end;
function Tclock.stringtoint_int(value:string):integer;
begin
result:=3600*strtoint(copy(value,1,2))+60*strtoint(copy(value,4,2))+strtoint(copy(value,7,2));
end;
Procedure Tclock.WMSize(var Message:TWMSize);
var w,h:integer;
begin
inherited;
w:=width;
h:=height;
if w<font.size*length(FDateTimeFormat) then
w:=font.size*length(FDateTimeFormat);
if h<font.size then
h:=font.Size;
if (w<>width) or (h<>height) then
inherited SetBounds(left,top,w,h);
message.Result:=0;
end;
procedure Tclock.PanelMouseDown(sender:TObject; Button:TMouseButton; Shift:TShiftstate; X,Y:integer);
begin
releasecapture;
perform(WM_SysCommand,$F012,0);
end;
procedure Tclock.TimeronTime(sender:TObject);
begin
FNow:=Now;
if FCaption<>FormatDateTime(FDateTimeFormat,FNow) then
begin
FCaption:=FormatDateTime(FDateTimeFormat,FNow);
Tpanel(self).Caption:=FCaption;
end;
if not FBusy then
begin
FBusy:=True;
try
CheckBeep;
CheckDateHint;
finally
FBusy:=False
end;
end;
end;
procedure Tclock.CheckBeep;
var h,m,s,ss:word;
begin
DecodeTime(FNow,h,m,s,ss);
if ((m=0)and (s=0)) or ((m=59)and (s>=60-h)) then
begin
if FBeep then
showmessage('整点报时');//可在此嵌入汇编,使计算机发声。
end;
end;
procedure Tclock.CheckdateHint;
var s,sdate,shint:string;
i:integer;
begin
for i:=0 to FDateHints.Count -1 do
begin
s:=FDateHints;
sDate:=Copy(s,1,pos('|',s)-1);
shint:=Copy(s,pos('|',s)+1,Length(s));
if stringtoint_char(FCaption)=stringtoint_int(sDate) then //如果比较两个字符串,始终没有相同情况,因为中英文中":"不同。
begin
FDateHint:=sHint; //可在此嵌入汇编,使计算机发声。
if assigned(FShowDateHint) then
FShowDateHint(self)
else
showmessage(shint);
end; end;
end;
procedure Tclock.SetDateHints(value:TStrings);
begin
FDateHints.Assign(value);
end;
procedure Tclock.EnableTimer(value:boolean);
begin
FActive:=value;
Timer.Enabled:=FActive;
end;
end.