The first method, using a "procedure call"
Procedure Del; // custom procedure var the Mutex: THandle; the begin the Mutex: = the CreateMutex ( nil , True, the PChar (Application.Title)); IF the GetLastError = ERROR_ALREADY_EXISTS the then the begin Application.MessageBox ( '! repeat login', 'prompted ' , MB_ICONERROR); the ReleaseMutex (the Mutex); { release resources } Application.Terminate; End ; End ;
The second way: by writing dpr project file
program Project1; uses Forms, windows, Unit1 in 'Unit1.pas' {Form1}; {$R *.RES} var Mutex:THandle; begin Mutex := CreateMutex(nil,true,'one'); {第3个参数任意设置} if GetLastError <> ERROR_ALREADY_EXISTS then begin Application.Initialize; Application.CreateForm(TForm1, Form1); Application.Run; end else Application.MessageBox('Repeat login! ' , ' Prompted ' , MB_OK); the ReleaseMutex (the Mutex); { release resources } End .