Happy Day.

This function might be of use for you...

procedure ExecuteAndWait (executable: string);
var
  StartupInfo: TStartupInfo;
  ProcessInfo: TProcessInformation;
  CreatedOK: boolean;
  status: integer;
  ev: TEvent;
  i: integer;
begin
  ev := TEvent.Create(nil, False, False, 'TimeKiller');
  try
    FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
    with StartupInfo do
    begin
      cb := SizeOf(TStartupInfo);
      dwFlags := STARTF_USESHOWWINDOW or STARTF_FORCEONFEEDBACK;
      wShowWindow := SW_HIDE;
    end;

    CreatedOk := CreateProcess(nil, PChar(executable),
                               nil, nil, False, NORMAL_PRIORITY_CLASS, nil, nil,
                               StartupInfo, ProcessInfo);
    if CreatedOK then
    begin
      { Wait around for the process to end. }
      with ProcessInfo do
      begin
        WaitForInputIdle(hProcess, INFINITE);
        GetExitCodeProcess(hProcess, status);
        while status = STILL_ACTIVE do
        begin
          GetExitCodeProcess(hProcess, status);
          { A quarter second delay here so this process doesn't hog CPU }
          ev.WaitFor(250);
          Application.ProcessMessages;
        end;
        CloseHandle(hThread);
        CloseHandle(hProcess);
      end; { with ProcessInfo }
    end; {if CreatedOK }
  finally
    ev.Free;
  end;
end;


Cheers.
                        BJ...

----------
From:   Alistair George[SMTP:[EMAIL PROTECTED]]
Reply To:       [EMAIL PROTECTED]
Sent:   Monday, 12 April 1999 09:26
To:     Multiple recipients of list delphi
Subject:        [DUG]:  Execute and wait?

Hi. I have an online registration proc, which gets the user to enter some
info, then executes another routine as below. Problem is, there is no wait
for the external dialog (the mail routine) to complete. It works, but is
messy. Can anyone suggest how to hold it till the mail box has minimized.
ExecuteFile('mailto:[EMAIL PROTECTED]?subject='+regstring, '', '',
SW_SHOWNOACTIVATE);
Application.HelpJump('OnlineOrder');//this executes immediately.

---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz

---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz

Reply via email to