你可以在工程的dpr文件中作如下改动: program Project1;uses Forms, Windows, SysUtils, Unit1 in 'Unit1.pas' {Form1};{$R *.RES} var hMutex:HWND; Ret:Integer; begin Application.Initialize; Application.Title:='Program Run Once Test'; hMutex:=CreateMutex(nil,False,'Program Run Once Test'); Ret:=GetLastError; if Ret<>ERROR_ALREADY_EXISTS then begin Application.CreateForm(TForm1, Form1); Application.Run; end else Application.MessageBox('本程序已在运行,您不能再次运行本程序!','警告',MB_OK); ReleaseMutex(hMutex); end.
program Project1;uses
Forms,
Windows,
SysUtils,
Unit1 in 'Unit1.pas' {Form1};{$R *.RES}
var
hMutex:HWND;
Ret:Integer;
begin
Application.Initialize;
Application.Title:='Program Run Once Test';
hMutex:=CreateMutex(nil,False,'Program Run Once Test');
Ret:=GetLastError;
if Ret<>ERROR_ALREADY_EXISTS then
begin
Application.CreateForm(TForm1, Form1);
Application.Run;
end
else
Application.MessageBox('本程序已在运行,您不能再次运行本程序!','警告',MB_OK);
ReleaseMutex(hMutex);
end.