appautorun OnAutoRun event
Return to Introduction  Previous page  Next page
Applies to
acAppAutoRun component.  

Declaration
property OnAutoRun: TNotifyEvent;  

Description
The OnAutoRun event occurs only when the program has been started on the Windows startup (after system reboot). If program started manually or by another program — OnAutoRun will not occurs.  
 
On starting the application, acAppAutoRun component will check whether the '/autorun' argument are presented between the command line parameters. If the ParamStr(1) contains the '/autorun' line, the OnAutoRun occurs to inform the application about automatic starting on Windows startup  

Example
procedure TForm1.acAppAutoRun1AutoRun(Sender: TObject);  
begin  
  Application.ShowMainForm := False;  
  acTrayIcon1.MinimizeToTray;  
end;  

{ ...or, in case if you are using acAppEvents component to manage Application properties, you can write following handler for OnAutoRun event: }  
procedure TForm1.acAppAutoRun1AutoRun(Sender: TObject);  
begin  
  acAppEvents1.ShowMainForm := False;  
  acAppEvents1.ShowTaskIcon := False;  
  acTrayIcon1.MinimizeToTray;  
end;  



tip You can also check this parameter yourself, to identify whether the program was started automatically or by user. For example, if the program was started on Windows startup, you want to make some specific operations without showing the main form:  
 
program MyProgram;  
 
uses  
  Forms,  
  Main in 'Main.pas' {Form1};  
 
{$R *.RES}  
 
begin  
  if ParamStr(1) = '/autorun' then  
   begin  
    // ... some operations  
   end  
  else  
   begin  
    Application.Initialize;  
    Application.CreateForm(TForm1, Form1);  
    Application.Run;  
   end;   
end.  

See also
AutoRun property.