onlyone TacOnlyOne component
Hierarchy Properties Methods Events
Return to Introduction  Previous page  Next page
The acOnlyOne component detects already running instances of the application and disallow to start the second copy of the same program.  
After detecting of the second application instance, acOnlyOne will automatically terminate program execution and switch the tasks to previous program instance (if SwitchToFirst property is True). If you wish to take some specific actions if another application instance detected (application already running) — write OnAlreadyExists event handler.  

new! The acOnlyOne unit now exports several functions which can be used outside of the component, in the initialization section of your application (*.DPR unit), so you can close second application instance and switch the input focus to previous, before the second instance will create any form.  
Here is an example (procedures exported from acOnlyOne unit marked with red color):  
program YourAppTitle;  
  Main in 'Main.pas' {MainForm};  
{$R *.res}  
  if HasParamStr('/close'then  
  // The Application.Title should be initialized before checking whether the application instance exists  
  Application.Title := 'YourAppTitle';  
  if IsAppInstanceAlreadyExists then  
    InfoBox('The application already running!');  
  Application.CreateForm(TMainForm, MainForm);