建立一个监控程序,如果到规定时间自动执行指定的操作,源代码:
定时拨号
-----------------------------
procedure TMainForm.Timer1Timer(Sender: TObject);
var shuttime: TDateTime;
begin
shuttime:=Now;
if (TimeToStr(shuttime)='19:58:01') or (TimeToStr(shuttime)='19:58:02') then
begin
if ConnList.ItemIndex = -1 then exit ;
if CurrConnection <> '' then exit ; // already connected
Timer.Enabled := false ; // must stop progress events during connection
RAS.EntryName := ConnList.Items [ConnList.ItemIndex]; // Connection name
CurrConnection := RAS.EntryName ; // keep it to check later
StopFlag := false ; // set if Disconnect button is pressed
Status.Panels[1].Text := '' ;
Status.Panels[1].Text := CurrConnection + ' - Starting Connection' ;
if RAS.AutoConnect <> 0 then // get phone book, start connection
begin
CurrConnection := '' ;
Timer.Enabled := true ;
Status.Panels[1].Text := 'Connection Failed - ' + RAS.StatusStr ;
beep ;
exit ;
end ;
// need to wait for connection to dial or whatever
while (RAS.ConnectState < RASBase) do
begin
Application.ProcessMessages ;
if StopFlag then break ; // see if Disconnect button pressed
end ;
Timer.Enabled := true ;
if (RAS.ConnectState <> RASCS_Connected) or StopFlag then
begin
Ras.Disconnect;
CurrConnection := '' ;
StateChanged (self) ; // update panel
Status.Panels[1].Text := 'Connection Terminated' ;
beep ;
exit ;
end ;
Status.Panels[1].Text := 'Connection Opened OK' ;
end;
end;
------------------------------------------------
定时触发事件
procedure TForm1.Timer1Timer(Sender: TObject);
var shuttime: TDateTime;
begin
shuttime:=Now;
if (TimeToStr(shuttime)='20:17:01') or (TimeToStr(shuttime)='20:17:02') then
label1.Caption :=TimeToStr(shuttime)
else if (TimeToStr(shuttime)='20:18:01') or (TimeToStr(shuttime)='20:18:02') then
label2.Caption :=TimeToStr(shuttime)
else if (TimeToStr(shuttime)='20:19:01') or (TimeToStr(shuttime)='20:19:02') then
label3.Caption :=TimeToStr(shuttime);
end;
------------------------------------------------
如有问题请来信:sunyl@dongyubooks.com
Good Lucky!!!!!!