Oppure

Loading
06/04/12 12:29
systemgvp
Salve

Io utilizzo un'applicazione esterna al mio progetto, per estrarre dei file presenti in un archivio compresso e, una volta estratti, mi mostra il contenuto di uno di essi, in questo modo:

[CODE]

ShellExecute(0,'open',pchar(cartellaprogramma+'Conv7z.exe'),pchar(parametri),nil,0);

//mostra dati
Memo2.Lines.LoadFromFile(cartellaTemporanea+'\'+NomeProgetto+'\progetto.txt');

[/CODE]

il problema è che affinchè possa verificarsi il LoadFromFile è necessario che il file sia stato già creato, ovvero attendere che tutto il processo di estrazione sia finito. E' possibile "sospendere" la mia applicazione finchè l'applicazione avviata con ShellExecute() non abbia avuto termine?
aaa
06/04/12 12:42
Goblin
In archivio ho trovato questa, non ricordo dove l'ho presa, magari fa al caso tuo

function WinExecAndWait(FileName:String; Visibility : integer):Cardinal;
var
  StartupInfo:TStartupInfo;
  ProcessInfo:TProcessInformation;
begin
  FillChar(StartupInfo,Sizeof(StartupInfo),#0);
  StartupInfo.cb := Sizeof(StartupInfo);
  StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
  StartupInfo.wShowWindow := Visibility;
  if not CreateProcess(nil,
    PChar(FileName),             { pointer to command line string }
    nil,                  { pointer to process security attributes}
    nil,                  { pointer to thread security attributes }
    false,                { handle inheritance flag }
    CREATE_NEW_CONSOLE or { creation flags }
    NORMAL_PRIORITY_CLASS,
    nil,                  { pointer to new environment block }
    nil,                  { pointer to current directory name }
    StartupInfo,          { pointer to STARTUPINFO }
    ProcessInfo) then     { pointer to PROCESS_INF }
      Result := 0
  else
  begin
    WaitforSingleObject(ProcessInfo.hProcess,INFINITE);
    GetExitCodeProcess(ProcessInfo.hProcess,Result);
  end;
end;

Ibis redibis non morieris in bello
06/04/12 13:12
smanettone83

prova con
try
ShellExecute(0,'open',pchar(cartellaprogramma+'Conv7z.exe'),pchar(parametri),nil,0);
finally
Memo2.Lines.LoadFromFile(cartellaTemporanea+'\'+NomeProgetto+'\progetto.txt');
end;

Ultima modifica effettuata da smanettone83 06/04/12 13:12
aaa
07/04/12 10:07
systemgvp
Grazie, ho risolto con:

[CODE]
uses ShellAPI, Winapi.Windows

procedure ApriEseguibileConAttesaFine(NomeDelFile: string; Parametri: string);

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(Parametri);
lpFile := PChar(NomeDelFile);
nShow := 0;
end;
if ShellExecuteEx(@exInfo) then Ph := exInfo.HProcess
else begin ShowMessage(SysErrorMessage(GetLastError)); Exit; end;
while WaitForSingleObject(ExInfo.hProcess, 50) <> WAIT_OBJECT_0 do Application.ProcessMessages;
CloseHandle(Ph);
end;

ApriEseguibileConAttesaFine('Applicazione.exe', 'parametri');
[/CODE]
aaa