关闭,在shellexecute之后彻底销毁MainForm - Delphi

时间:2014-07-04 12:57:37

标签: forms delphi destroy forceclose

我必须为exe文件开发一个启动程序,但是我在关闭mainform时遇到了一些麻烦。

我想继续打开可执行文件但关闭表单。 我通过执行应用程序取得了成功,执行了.exe并且表单已经关闭" .exe打开后。这几乎是我想要的,但launcher.exe仍然在Windows任务管理器中处于活动状态。

这是执行.exe:

的过程
procedure TForm2.LancerVersion(aExe: String);
var
  SEInfo: TShellExecuteInfo;

begin
  FillChar(SEInfo, SizeOf(SEInfo), 0);
  SEInfo.cbSize := SizeOf(TShellExecuteInfo);
  with SEInfo do
  begin 
    fMask := SEE_MASK_NOCLOSEPROCESS;
    Wnd := Application.Handle;
    lpFile := PChar(aExe);
    nShow := SW_SHOWNORMAL;
  end;    
  ShellExecuteEx(@SEInfo);
  if Blight then
   begin
    free;
    Close; **//HERE I WOULD LIKE TO CLOSE CLEANLY MY FORM**
   end 
  else
   hide;
end;

这是结束的自定义程序:

procedure TForm2.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
    if BClose then
    begin
      Canclose := false;
      Bshow := false;
    end;
    Canclose := true; **//IT GOES HERE AFTER CLOSE IS CALLED**
end;

我已经编写了这个自定义程序,因为有时我只想在点击X窗口的按钮时在参数功能中隐藏窗体。所以,不要关心第一个条件"如果Bclose那么"。

我确保自己释放我在FormCreate中创建的FormDestroy中的所有对象,但没有任何事情可做,该进程仍然存在......

如果你能帮助我,或者只是看看我的问题,我会感激不尽。 提前谢谢..

1 个答案:

答案 0 :(得分:2)

这是一个小型的SSCCE:

procedure TForm1.Button1Click(Sender: TObject);

var
  SEInfo: TShellExecuteInfo;
  ExecuteFile: string;

begin
  ExecuteFile := 'notepad.exe';
  FillChar(SEInfo, SizeOf(SEInfo), 0);
  SEInfo.cbSize := SizeOf(TShellExecuteInfo);
  with SEInfo do
  begin
    Wnd := Application.Handle;
    lpFile := PChar(ExecuteFile);
    nShow := SW_SHOWNORMAL;
  end;
  Win32Check(ShellExecuteEx(@SEInfo));
  Close;
end;

问题在于你在程序中调用Free,不要这样做。

相关问题