[対象バージョン]
Delphi 2.0J/3.0J
[説明]
他のアプリケーションを起動して、それが終了するまで命令を実行しないように待機させる方法です。
[対処法]
Windows API の CreateProcess を使用してプログラムを起動します。その際取得したハンドルを利用して WaitForSingleObject を呼びだしプログラムの終了を判断します。
[サンプルソース]
procedure TForm1.Button1Click(Sender: TObject); var SI: TStartupInfo; PI: TprocessInformation; dummy: integer ; begin {現在のプログラムのスタートアップ情報を取得} GetStartupInfo(SI); {他のアプリケーションの起動} if not CreateProcess(PChar('c:\windows\Calc.exe'), nil, nil, nil, False, CREATE_DEFAULT_ERROR_MODE, nil, nil, SI,PI) then {CreateProcess が False を返したときはエラー} raise Exception.Create('calc.exe を起動できません'); {起動した他のアプリケーションの終了を待つ} While WaitForSingleObject(PI.hProcess, 0) = WAIT_TIMEOUT do {他のアプリケーションが処理が行えるようにする} Application.ProcessMessages; {他のアプリケーション終了後の処理} dummy := Application.MessageBox('終了しました','',MB_OKCANCEL); end;