Suppose I clicked on the program's shortcut, the program started, hid out after a while with the help of Hide, click on the shortcut a second time and it unfolds and becomes visible in the foreground if there are many windows running?

    2 answers 2

    Use mutexes (mutex). You can think of it as a global variable at the operating system level.

    Select a name, for example "MyAppMutex" . When launching the application, create a mutex with this name. If the mutex is created successfully, we continue to work; if not, terminate the application.

    See CreateMutex


    UPD0

     program Project1; uses Forms, Windows, Messages, Unit1 in 'Unit1.pas' {Form1}; {$R *.res} var Mutex : THandle; begin Mutex := CreateMutex(nil, True, 'My_Unique_Application_Mutex_Name'); if (Mutex <> 0) and (GetLastError <> ERROR_ALREADY_EXISTS) then begin Application.Initialize; Application.CreateForm(TForm1, Form1); Application.Run; if Mutex <> 0 then begin CloseHandle(Mutex); end; end; end. 
    • I'm sorry, I did not get it! Explain, please!!! - delphikettle

    In the project file:

     var xHand: THandle; begin xHand:=CreateMutex(nil,false,'206f731a-73a3-4b07-bb35-1f858cb8fb67'); If (GetLastError = ERROR_ALREADY_EXISTS) then MessageDlg(' Уже запущено! ',mtInformation, [mbOk], 0); Application.Initialize; Application.CreateForm(TMainForm, MainForm); Application.Run; ReleaseMutex(xHand); end.