Close and restart the current application in DELPHI

DRokie picture DRokie · May 16, 2011 · Viewed 22.4k times · Source

How can I do this one?

For some reason or selected by the user, “ask” the current application to restart it self.

Answer

Andreas Rejbrand picture Andreas Rejbrand · May 16, 2011
uses ShellAPI;

...

procedure TForm1.RestartThisApp;
begin
  ShellExecute(Handle, nil, PChar(Application.ExeName), nil, nil, SW_SHOWNORMAL);
  Application.Terminate; // or, if this is the main form, simply Close;
end;