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

procedure CloseFirstInstance;  

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 CloseFirstAppInstance procedure, exported from acOnlyOne unit, and use following code in the main ".DPR" unit of your program. This example demonstrates how to kill previous program instance and close itself without creating any forms:  
program YourProgramName;  
  Main in 'Main.pas' {MainForm};  
{$R *.RES}  
  if HasParamStr('/close'then  
  Application.Title := 'YourProgramTitle';  
  Application.CreateForm(TMainForm, MainForm);  

iiinfo Also you can check out the CloseApp command-line tool in the "Tools" directory of distribution package. That utility can be used to close ANY application which uses TacOnlyOne component, all you need is just specify the the application title as command-line parameter. This can be very useful for silent installations which should close the installation instance before overwrite it.  
Usage of CloseApp.exe is following:  
  CloseApp.exe [ApplicationTitle]  
For example:  
  CloseApp.exe MyAppTitle  

See also
CloseFirst and CloseSecond properties;  
OnAlreadyExist event.