Bonjour à tous,
J'utilise cette fonction ShellExecuteEx sous Windows pour lancer une autre application et attendre la fin de son exécution.
Cela fonctionne très bien. Voir le code ci-joint.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
 
uses ShellAPI;
 
function ShellExecute_AndWait(FileName: string; Params: string): bool;
var
  exInfo: TShellExecuteInfo;
  Ph: DWORD;
begin
 
  FillChar(exInfo, SizeOf(exInfo), 0);
  with exInfo do
  begin
    cbSize := SizeOf(exInfo);
    fMask := SEE_MASK_NOCLOSEPROCESS or SEE_MASK_FLAG_DDEWAIT;
    Wnd := GetActiveWindow();
    exInfo.lpVerb := 'open';
    exInfo.lpParameters := PChar(Params);
    lpFile := PChar(FileName);
    nShow := SW_SHOWNORMAL;
  end;
  if ShellExecuteEx(@exInfo) then
    Ph := exInfo.hProcess
  else
  begin
    ShowMessage(SysErrorMessage(GetLastError));
    Result := true;
    exit;
  end;
  while WaitForSingleObject(exInfo.hProcess, 50) <> WAIT_OBJECT_0 do
    Application.ProcessMessages;
  CloseHandle(Ph);
 
  Result := true;
 
end;
Je voudrai faire la même chose sur un Mac.
J'ai trouvé ce code qui utilise une NSTask.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 
private
Task: NSTask;
 
 
procedure TMainForm.Exec(FileName: PWideChar);
begin
Task := TNSTask.Wrap(TNSTask.Wrap(TNSTask.OCClass.alloc).init);
 
Task.setLaunchPath(StrToNSStr(FileName));
 
Task.launch;
Task.waitUntilExit;    //This child process is supposed to keep running.
end;
 
procedure TMainForm.FormCreate(Sender: TObject);
begin
Task := nil;
end;
 
procedure TMainForm.FormDestroy(Sender: TObject);
begin
if (Task <> nil)
then
begin
Task.release;
Task := nil;
end;
end;
Mais il ne fonctionne pas. La NSTask n'est pas reconnue avec Delphi 11 et 12.
Savez-vous dans quelle unité elle est déclarée?
Merci.