小
小師妹
Unregistered / Unconfirmed
GUEST, unregistred user!
提示:file not found:OnlyOne.res;编译不能通过。
代码如下:
unit OnlyOne;
interface
uses
// Forms,
messages, Dialogs,
windows,
Registry,
Sysutils;
procedure OnlyOneApplicationRun(ThisTitle : String) ;
implementation
{$R *.RES}
procedure OnlyOneApplicationRun(ThisTitle : String) ;
var
Reg : TRegistry;
ApplicationTitle: string;
hMutex : THandle;
Ret : Integer;
begin
// ThisTitle := 'Htgl'; //不能用ThisTitle := Application.Title;
Reg:=TRegistry.Create;
Reg.RootKey:=HKEY_LOCAL_MACHINE;
if Reg.OpenKey('SoftWare/BookStar/OnlyOne',True) then
ApplicationTitle := Reg.ReadString('ProgramTile');
hMutex:=CreateMutex(nil,False,PChar(ApplicationTitle));
Ret:=GetLastError;
if (trim(ApplicationTitle)='') or (Ret<>ERROR_ALREADY_EXISTS) then
Reg.writeString('ProgramTile',ThisTitle)
else
begin
showmessage('无法启动当前程序,因为一个名为"'+ApplicationTitle+'"的进程已经打开数据库。');
// MessageBox('',PChar('无法启动当前程序,因为一个名为"'+ApplicationTitle+'"的进程已经打开数据库。'),'提示',MB_ICONERROR or MB_OK);
ReleaseMutex(hMutex);
Reg.CloseKey;
Reg.Free;
halt;
Exit;
end;
ReleaseMutex(hMutex);
Reg.CloseKey;
Reg.Free;
end;
end.
代码如下:
unit OnlyOne;
interface
uses
// Forms,
messages, Dialogs,
windows,
Registry,
Sysutils;
procedure OnlyOneApplicationRun(ThisTitle : String) ;
implementation
{$R *.RES}
procedure OnlyOneApplicationRun(ThisTitle : String) ;
var
Reg : TRegistry;
ApplicationTitle: string;
hMutex : THandle;
Ret : Integer;
begin
// ThisTitle := 'Htgl'; //不能用ThisTitle := Application.Title;
Reg:=TRegistry.Create;
Reg.RootKey:=HKEY_LOCAL_MACHINE;
if Reg.OpenKey('SoftWare/BookStar/OnlyOne',True) then
ApplicationTitle := Reg.ReadString('ProgramTile');
hMutex:=CreateMutex(nil,False,PChar(ApplicationTitle));
Ret:=GetLastError;
if (trim(ApplicationTitle)='') or (Ret<>ERROR_ALREADY_EXISTS) then
Reg.writeString('ProgramTile',ThisTitle)
else
begin
showmessage('无法启动当前程序,因为一个名为"'+ApplicationTitle+'"的进程已经打开数据库。');
// MessageBox('',PChar('无法启动当前程序,因为一个名为"'+ApplicationTitle+'"的进程已经打开数据库。'),'提示',MB_ICONERROR or MB_OK);
ReleaseMutex(hMutex);
Reg.CloseKey;
Reg.Free;
halt;
Exit;
end;
ReleaseMutex(hMutex);
Reg.CloseKey;
Reg.Free;
end;
end.