Environment:
* Lazarus 2.0.2/FPC 3.0.4
* Ubuntu 12.04
Problem:
I have a small GUI program which processes a series of files by calling a external program with TAsyncProcess.
I'm using TAsyncProcess specifically because it has the OnTerminate event
but it never gets called!.
The processing starts on a button click:
procedure TMainForm.btPlayAllClick(Sender: TObject);
begin
btPlayAll.Enabled := False;
PlayList := True;
Current := -1;
btNext.Click;
end;
The
OnClick event for
btNext (another button) does some housekeeping and starts playing one song:
procedure TMainForm.btNextClick(Sender: TObject);
var
Max: Integer;
begin
Max := FileList.Count - 1;
if (Max > 0) then begin
if Current < Max then
PlaySong(Current + 1)
else
PlaySong(0);
end;
end;
PlaySong gets just setups the parameters for
TAsyncProcess and Executes it. That part works ok but ...when the AsyncProcess terminates it should call the handler for its
OnTerminate event which just happens to advance to the next file and play it:
procedure TMainForm.ProcessTerminate(Sender: TObject);
{ When in "playlist" mode it should either play the next file
or stop if it's the last, but ... it never gets called! }
var
Max: Integer;
begin
{@test}ShowMessage('Process terminated'); {<-- Never appears!!!}
StatusBar.SimpleText := sStopped;
Max := FileList.Count - 1;
if PlayList then
if (Current < Max) then
PlaySong(Current+1);
else begin
PlayList := False;
btPlayAll.Enabled := True;
end;
end;
As it says, it never gets called , so clicking the "Play all" button just plays the first file.
And no, I didn't forget to set the
OnTerminate event.
Any help?
In case it matters, I'm attaching the whole project. It's quite crude, just a quick first iteration to test the concept. It'll be trashed after the redesign once it has served its purpose, so don't be too critical with it.