Here is my working code:
//Processandwait example by Amnon82
//Version 20070312-1
//
//Create a form with one button on it.
//Copy this sourcecode to your pas.
//Compile it in lazarus.
unit unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, Buttons, Process;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{ TForm1 }
procedure Processandwait(Executable : String);
var
AProcess1: TProcess;
exitcode, i : integer;
begin
I:= 0;
try
AProcess1 := TProcess.Create(nil);
AProcess1.CommandLine := Executable;
AProcess1.Options := AProcess1.Options;
{Execute}
AProcess1.Execute;
{Wait to finish}
while AProcess1.running = true do
begin
I:= I + 1;
sleep (300);
form1.caption := ' L:'+ inttostr(i);
Application.ProcessMessages;
end;
finally
AProcess1.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Processandwait('gedit');
Showmessage('gedit closed');
end;
initialization
{$I unit1.lrs}
end.