Delphi编写系统服务三:编写两栖系统服务
Delphi编写系统服务三:编写两栖系统服务 收藏
采用下面的方法,可以实现一个两栖系统服务(既系统服务和桌面程序的两种模式)
工程代码:
program FleetReportSvr;
uses
SvcMgr,
Forms,
SysUtils,
Windows,
SvrMain in 'SvrMain.pas' {FleetReportService: TService},
AppMain in 'AppMain.pas' {FmFleetReport};
{$R *.RES}
const
CSMutexName = 'Global\Services_Application_Mutex';
var
OneInstanceMutex: THandle;
SecMem: SECURITY_ATTRIBUTES;
aSD: SECURITY_DESCRIPTOR;
begin
InitializeSecurityDescriptor(@aSD, SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(@aSD, True, nil, False);
SecMem.nLength := SizeOf(SECURITY_ATTRIBUTES);
SecMem.lpSecurityDescriptor := @aSD;
SecMem.bInheritHandle := False;
OneInstanceMutex := CreateMutex(@SecMem, False, CSMutexName);
if (GetLastError = ERROR_ALREADY_EXISTS)then
begin
DlgError('Error, Program or service already running!');
Exit;
end;
if FindCmdLineSwitch('svc', True) or
FindCmdLineSwitch('install', True) or
FindCmdLineSwitch('uninstall', True) then
begin
SvcMgr.Application.Initialize;
SvcMgr.Application.CreateForm(TSvSvrMain, SvSvrMain);
SvcMgr.Application.Run;
end
else
begin
Forms.Application.Initialize;
Forms.Application.CreateForm(TFmFmMain, FmMain);
Forms.Application.Run;
end;
end.
然后在SvrMain注册服务:
unit SvrMain;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs, MsgCenter;
type
TSvSvrMain = class(TService)
procedure ServiceStart(Sender: TService; var Started: Boolean);
procedure ServiceStop(Sender: TService; var Stopped: Boolean)
相关文档:
Delphi的VCL框架在创建应用时TApplication是一个自动创建的隐藏窗口,其它创建的窗口是自动以该窗口为窗口,这就导致创始的主窗口在任务栏的系统菜单只有三项,只要在主窗口的Create事件中将系统菜单用Application的系统菜单替换,并将SysCommand消息转发到主窗口就正常了。
unit Unit1;
interface
uses
Windows ......
1.SHIFT+鼠标左键 先选中任一控件,按键后可选中窗体(选中控件后按Esc效果一样)
2.Shift+F8 调试时弹出CPU窗口。
3.Shift+F10 等于鼠标右键(Windows快捷键)。
&n ......
一直想让Delphi做为RIA,而业务层使用Java!今天没事做,简单实现了一下!
目前有2种方案:
WebService
IndyHttp调用Servlet
以下是用IndyHttp来调用Servlet
一、先写一个helloworld的Servlet
1.编写ui以及service
//工具包
package com.cdrs.jutils;
import java.io.IOException;
import java.util.Date;
impor ......
var
L,i:integer;
Ustr,str:string;
p:char;
begin
str:='123456789ABCDEFG'
L:=length(str);
for i:=1 to l do begin
p:=str[i];
str[i]:=str[l-(i-1)];
......