1. Use createmutex
Createmutex (nil, false, 'project ');
Result: = true;
If getlasterror = error_already_exists then
Begin
// Sendmessage (msg_close_win, registerwindowmessage ('project'), 0, 0); // hwnd_broadcast
Close;
Showmessage ('you have the program running allready !! ');
Halt (0 );
Result: = false; // True False
End;
2. Use sendmessage and findwindow (Class Name, caption ),)
Sendmessage (findwindow ('tfrmsimulator', nil), wm_close, 0, 0); // Simulator
3. globalfindatom (this function must be destroyed)
{Search table to see if the program is running}
If globalfindatom ('program _ running') = 0 then
{If it is not running, add information in the table}
Atom: = globaladdatom ('program _ running ')
Else begin
{If the program is running, the system displays information and exits}
Messagedlg ('you have the program running
All ready !! ', Mtwarning, [mbok], 0 );
Halt;
End;
Procedure tform1.formdestroy (Sender: tobject );
Begin
{Remove information from the table so that the program can run again}
Globaldeleteatom (atom );
End;
If you want to disable the previous one and try again, we recommend that you use 2. We recommend that you do not use 3.