首页 新闻 会员 周边 捐助

在win7,启动不了delphi开发的服务

0
悬赏园豆:5 [已关闭问题] 关闭于 2015-01-19 15:44

如题在win7,启动不了delphi开发的服务


只绑定了OnStart、OnStop、OnPause、事件
求指点哪块错了...分数只有这些了=.=

  
1
unit ClientOnLines; 2 3 interface 4 5 uses 6 Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr,IdTCPServer,Sockets, 7 IdBaseComponent, IdComponent, IdTCPConnection, Variants, 8 Dialogs, IdUDPServer, IdUDPBase, IdUDPClient, IdTCPClient, ExtCtrls, 9 StdCtrls, Buttons, ComCtrls, IdThreadMgr, IdThreadMgrDefault,Unit1; 10 11 type 12 MsgData=Record //TCP通信参数 13 Code :string; 14 TimeOff :string; 15 MD5 :string;//加密数据MD5 16 End; 17 18 TClientOnline = class(TService) 19 Client: TIdTCPClient; 20 Connect_Timer: TTimer; 21 Send_Timer: TTimer; 22 procedure ServiceStart(Sender: TService; var Started: Boolean); 23 procedure Connect_TimerTimer(Sender: TObject); 24 procedure Send_TimerTimer(Sender: TObject); 25 procedure ServiceStop(Sender: TService; var Stopped: Boolean); 26 procedure ServicePause(Sender: TService; var Paused: Boolean); 27 private 28 { Private declarations } 29 public 30 function GetServiceController: TServiceController; override; 31 { Public declarations } 32 end; 33 34 var 35 ClientOnline: TClientOnline; 36 TimeOff:Integer; 37 Data:MsgData; 38 ServiceIP:string; 39 Port:Integer; 40 IsNetwork : Boolean;//是否链接上 41 function Connect:Boolean; 42 function WriteLog(Msg:string):Boolean; 43 function Send(SendData:MsgData):Boolean; 44 45 implementation 46 47 {$R *.DFM} 48 49 procedure ServiceController(CtrlCode: DWord); stdcall; 50 begin 51 ClientOnline.Controller(CtrlCode); 52 end; 53 54 function TClientOnline.GetServiceController: TServiceController; 55 begin 56 Result := ServiceController; 57 end; 58 59 procedure TClientOnline.ServiceStart(Sender: TService; 60 var Started: Boolean); 61 begin 62 Started:=True; 63 Connect; 64 end; 65 66 //连接Service 67 function Connect:Boolean; 68 begin 69 TimeOff:=10; 70 ClientOnline.Client.Port:=8079; 71 ClientOnline.Client.Host:='192.168.0.105'; 72 try 73 ClientOnline.Client.Connect; 74 IsNetwork:=True; 75 ClientOnline.Connect_Timer.Enabled:=False; 76 ClientOnline.Send_Timer.Enabled:=True; 77 78 Data.Code:=IntTostr(WM_HearBeat); 79 Data.TimeOff:=IntTostr(TimeOff); 80 Data.MD5:=''; 81 Send(Data); 82 83 except//开启时钟 1分钟执行一次连接操作 84 ClientOnline.Connect_Timer.Enabled:=True; 85 IsNetwork:=False; 86 end; 87 Result:= IsNetwork; 88 end; 89 90 function WriteLog(Msg:string):Boolean; 91 begin 92 Result:=True; 93 end; 94 95 96 function Send(SendData:MsgData):Boolean; 97 begin 98 ClientOnline.Client.WriteBuffer(SendData, SizeOf(SendData), true); 99 Result:=True; 100 end; 101 102 //连接Timer执行方法 103 procedure TClientOnline.Connect_TimerTimer(Sender: TObject); 104 begin 105 if Connect then 106 begin 107 Data.Code:=IntTostr(WM_HearBeat); 108 Data.TimeOff:=IntTostr(TimeOff); 109 Data.MD5:=''; 110 Send(Data); 111 ClientOnline.Connect_Timer.Enabled:=False; 112 ClientOnline.Send_Timer.Enabled:=True; 113 end; 114 end; 115 116 procedure TClientOnline.Send_TimerTimer(Sender: TObject); 117 begin 118 119 Data.Code:=IntTostr(WM_HearBeat); 120 Data.TimeOff:=IntTostr(TimeOff); 121 Data.MD5:=''; 122 Send(Data); 123 end; 124 125 procedure TClientOnline.ServiceStop(Sender: TService; 126 var Stopped: Boolean); 127 begin 128 Stopped := True; 129 end; 130 131 procedure TClientOnline.ServicePause(Sender: TService; 132 var Paused: Boolean); 133 begin 134 Paused := True; 135 end; 136 137 end.
迷失路灯的主页 迷失路灯 | 初学一级 | 园豆:7
提问于:2014-07-22 20:07
< >
分享
所有回答(1)
0

哇,delphi ,学习了

jerry-Tom | 园豆:4077 (老鸟四级) | 2014-07-23 10:02
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册