function ScreenToMap(Zoom:Double;Margin:TPoint;ViewportOffset:TPoint;Extent:TExtent; const _ptg : TPoint ) : TGIS_Point ;
begin
if FZoom <= 0 then begin
Result := GisPoint(0, 0 ) ;
SysUtils.Abort ;
end ;
function StartSQLServer(szErrorMsg:string):Boolean;
在implementation部分写:
const
SERVICE_UNKNOWN =0;
type
enumSQLSCMCommands=(SQLSCMCmd_STOP,SQLSCMCmd_PAUSE,SQLSCMCmd_START,SQLSCMCmd_CONTINUE);
const
wn95scm='w95scm.dll';
// Function prototypes
function SQLSCMLocalServiceControlA(lpszSvc:LPSTR;iCommand:integer;
pdwErr:LPDWORD;iCount:integer;lpStartParameter:Pointer):BOOL;stdcall
external wn95scm name 'SQLSCMLocalServiceControlA';
function SQLSCMLocalServiceControlW(lpszSvc:LPWSTR;iCommand:integer;
pdwErr:LPDWORD;iCount:integer;lpStartParameter:Pointer):BOOL;stdcall
external wn95scm name 'SQLSCMLocalServiceControlW';
function SQLSCMGetLocalServiceStateA(lpszSvc:LPSTR;pdwErr:LPDWORD):DWORD;stdcall
external wn95scm name 'SQLSCMGetLocalServiceStateA';
function SQLSCMGetLocalServiceStateW(pwszSvc:LPWSTR;pdwErr:LPDWORD):DWORD;stdcall
external wn95scm name 'SQLSCMGetLocalServiceStateW';
{$ifdef UNICODE}
function SQLSCMLocalServiceControl(lpszSvc:LPSTR;iCommand:integer;
pdwErr:LPDWORD;iCount:integer;lpStartParameter:Pointer):BOOL;stdcall
external wn95scm name 'SQLSCMLocalServiceControlW';
function SQLSCMGetLocalServiceState(pwszSvc:LPWSTR;pdwErr:LPDWORD):DWORD;stdcall
external wn95scm name 'SQLSCMGetLocalServiceStateW';
{$else}
function SQLSCMLocalServiceControl(lpszSvc:LPSTR;iCommand:integer;
pdwErr:LPDWORD;iCount:integer;lpStartParameter:Pointer):BOOL;stdcall
external wn95scm name 'SQLSCMLocalServiceControlA';
function SQLSCMGetLocalServiceState(lpszSvc:LPSTR;pdwErr:LPDWORD):DWORD;stdcall
external wn95scm name 'SQLSCMGetLocalServiceStateA';
{$endif} // !UNICODE
function StartSQLServer(szErrorMsg:string):Boolean;
var
szService:LPSTR;
dwErr:PDWORD;
dwServiceState:DWORD;
bControlSuccessful:BOOL;
lsStr:string;
begin
result:=false;
szService := 'MSSQLServer';
bControlSuccessful:=TRUE;
dwServiceState := SQLSCMGetLocalServiceState(szService, dwErr);
while ((dwServiceState <>0) and (bControlSuccessful = TRUE))do
begin
if (dwServiceState = SERVICE_RUNNING) then
break;
case dwServiceState of
SERVICE_PAUSED:begin // Paused, so continue.
bControlSuccessful := SQLSCMLocalServiceControl(szService,
Ord(SQLSCMCmd_CONTINUE),dwErr, 0, nil);
end;
SERVICE_STOPPED:begin // Stopped, start service.
bControlSuccessful := SQLSCMLocalServiceControl(szService,
Ord(SQLSCMCmd_START), dwErr, 0, nil);
end;
else // Error if state is 0 otherwise state is changing.
begin
if (dwServiceState = 0) then
begin // Error. Return failure.
StrPCopy(PChar(dwErr),lsStr);
szErrorMsg:='Error '+lsStr+' on attempt to determine service state.';
exit;
end;
end;
end;
Sleep(5);
dwServiceState := SQLSCMGetLocalServiceState(szService, dwErr);
end;
if (bControlSuccessful) then
begin
StrPCopy(PChar(dwErr),lsStr);
szErrorMsg:='Error '+lsStr+' returned on attempt to change service state.';
end;
result:=bControlSuccessful;
end;