onlyone CloseFirstInstance method
Return to Introduction  Previous page  Next page
Applies to
acOnlyOne component.  

Declaration
procedure CloseFirstInstance;  

Description
The CloseFirstInstance method closes the previos instance of the application.  
 
tip Alternatively you can set CloseFirst property on startup and first program instance will be closed automatically.  
 
However, if you would like to close ALL instances of your application when, for example, your program started with "/close" command-line parameter, you can use following code in the main ".DPR" unit of your program. The example demonstrates how to kill previous program instance and close itself without creating any forms:  
 
program YourProgramName;  
 
uses  
  acOnlyOne,  
  acUtils,  
  Main in 'Main.pas' {MainForm};  
 
{$R *.RES}  
 
begin  
  if HasParamStr('/close'then  
   begin  
    CloseFirstAppInstance;  
    Exit;  
   end;  
 
  Application.Initialize;  
  Application.Title := 'YourProgramTitle';  
  Application.CreateForm(TMainForm, MainForm);  
  Application.Run;  
end.  

See also
CloseFirst and CloseSecond properties;  
OnAlreadyExist event.