TAlarmMng = class(TObject)
private
Timer:TTimer;
public
constructor Create(AOwner: TComponent);
destructor Destroy; override;
function Alarm(ATime:TdateTime):boolean;
procedure ShowMsg(Sender: TObject);
end;
function TAlarmMng.Alarm( ATime:TdateTime): boolean;
var
Interval:Int64;
Hour,Min,Sec,MSec:word;
begin
self.Timer.Interval:=2000;
self.Timer.Enabled:=true;
self.Timer.OnTimer:=self.ShowMsg;
end;constructor TAlarmMng.Create(AOwner: TComponent);
begin
inherited Create;
self.Timer:=TTimer.Create(AOwner);
self.Timer.Enabled:=false;
end;destructor TAlarmMng.Destroy;
begin inherited;
end;procedure TAlarmMng.ShowMsg(Sender: TObject);
begin
showmessage('你有新的消息');
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
AlarmMng:=TAlarmMNg.Create(self);
AlarmMng.Alarm(now);
end;
什么反应都没有。
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
AlarmMng:=TAlarmMNg.Create(self);
AlarmMng.ShowMsg(nil);
end;
可以显示信息框:‘你有新的消息’请问这是什么原因?
private
Timer:TTimer;
public
constructor Create(AOwner: TComponent);
destructor Destroy; override;
function Alarm(ATime:TdateTime):boolean;
procedure ShowMsg(Sender: TObject);
end;
function TAlarmMng.Alarm( ATime:TdateTime): boolean;
var
Interval:Int64;
Hour,Min,Sec,MSec:word;
begin
self.Timer.Interval:=2000;
self.Timer.Enabled:=true;
self.Timer.OnTimer:=self.ShowMsg;
end;constructor TAlarmMng.Create(AOwner: TComponent);
begin
inherited Create;
self.Timer:=TTimer.Create(AOwner);
self.Timer.Enabled:=false;
end;destructor TAlarmMng.Destroy;
begin inherited;
end;procedure TAlarmMng.ShowMsg(Sender: TObject);
begin
showmessage('你有新的消息');
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
AlarmMng:=TAlarmMNg.Create(self);
AlarmMng.Alarm(now);
end;
什么反应都没有。
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
AlarmMng:=TAlarmMNg.Create(self);
AlarmMng.ShowMsg(nil);
end;
可以显示信息框:‘你有新的消息’请问这是什么原因?
解决方案 »
- 加载数据量很大,怎么提高加载数据速度?
- 如何拦截关机、重启、注销的消息?
- 关于quickreport分页打印
- 记录定位问题,跪求达人赐教,急!!!
- 开发过主细表的大侠过来看看
- 期末考试终于考完了,高兴啊(2)!!!为什么我只能给100分啊???
- 有谁知道哪里有DELPHI5。0下载?
- 诚聘DELPHI+数据库高手!!!!!!!!!!
- Delphi中InputBox的OK和Cancel怎么改成中文?
- DirectDraw的Surface.getdc速度很慢,是吗?
- 请问在调用COM接口的时候为什么报"ole error C0000005"的错误?这个错误是什么意思呢?
- 我的编程手册“简单文档管理器”
//控件单元。
{
Copyright ?1999 by Delphi 5 Developer's Guide - Xavier Pacheco and Steve Teixeira
}unit halfmin;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls,
Forms, Dialogs, ExtCtrls;type
{ Define a procedure for the event handler. The event property will
be of this procedure type. This type will take two parameters, the
object that invoked the event and a TDateTime value to represent
the time that the event occurred. For our component this will be
every half-minute. }
TTimeEvent = procedure(Sender: TObject; TheTime: TDateTime) of object; TddgHalfMinute = class(TComponent)
private
FTimer: TTimer;
{ Define a storage field to point to the user's event handler.
The user's event handler must be of the procedural type
TTimeEvent. }
FOnHalfMinute: TTimeEvent;
FOldSecond, FSecond: Word; // Variables used in the code
{ Define a procedure, FTimerTimer that will be assigned to
FTimer.OnClick. This procedure must be of the type TNotifyEvent
which is the type of TTimer.OnClick. }
procedure FTimerTimer(Sender: TObject);
protected
{ Define the dispatching method for the OnHalfMinute event. }
procedure DoHalfMinute(TheTime: TDateTime); dynamic;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
// Define the actual property that will show in the Object Inspector
property OnHalfMinute: TTimeEvent read FOnHalfMinute write FOnHalfMinute;
end;implementationconstructor TddgHalfMinute.Create(AOwner: TComponent);
{ The Create constructor, creates the TTimer instanced for FTimer. It
then sets up the various properties of FTimer, including its OnTimer
event handler which is TddgHalfMinute's FTimerTimer() method. Notice
that FTimer.Enabled is set to true only if the component is running
and not while the component is in design mode. }
begin
inherited Create(AOwner);
// If the component is in design mode, do not enable FTimer.
if not (csDesigning in ComponentState) then
begin
FTimer := TTimer.Create(self);
FTimer.Enabled := True;
// Set up the other properties, including the FTimer.OnTimer event handler
FTimer.Interval := 500;
FTimer.OnTimer := FTimerTimer;
end;
end;destructor TddgHalfMinute.Destroy;
begin
FTimer.Free;
inherited Destroy;
end;procedure TddgHalfMinute.FTimerTimer(Sender: TObject);
{ This method serves as the FTimer.OnTimer event handler and is assigned
to FTimer.OnTimer at run-time in TddgHalfMinute's constructor. This method gets the system time, and then determines whether or not
the time is on the minute, or on the half-minute. If either of these
conditions are true, it calls the OnHalfMinute dispatching method,
DoHalfMinute. }
var
DT: TDateTime;
Temp: Word;
begin
DT := Now; // Get the system time.
FOldSecond := FSecond; // Save the old second.
// Get the time values, needed is the second value
DecodeTime(DT, Temp, Temp, FSecond, Temp); { If not the same second when this method was last called, and if
it is a half minute, call DoOnHalfMinute. }
if FSecond <> FOldSecond then
if ((FSecond = 30) or (FSecond = 0)) then
DoHalfMinute(DT)
end;procedure TddgHalfMinute.DoHalfMinute(TheTime: TDateTime);
{ This method is the dispatching method for the OnHalfMinute event.
it checks to see if the user of the component has attached an
event handler to OnHalfMinute and if so, calls that code. }
begin
if Assigned(FOnHalfMinute) then
FOnHalfMinute(Self, TheTime);
end;end.//调用代码procedure TForm1.ddgHalfMinute(sender;TheTime:TDateTime);
begin
ShowMessage('The Time Is '+TimeToSte
end;
begin
ShowMessage('The Time Is '+TimeToStr(TheTime));
end;