View Issue Details

IDProjectCategoryView StatusLast Update
0004169JEDI VCL00 JVCL Componentspublic2007-10-12 06:54
ReporterFireStormXAssigned Toobones 
PrioritynormalSeveritymajorReproducibilityalways
Status resolvedResolutionno change required 
Product Version3.00 
Target VersionFixed in Version 
Summary0004169: OnTerminate event does not fire when running from a console application.
DescriptionI can't get the OnTerminate event to fire when I use the JvCreateProcess component in a console application.

Reproduce:
Main console app:

begin
  { TODO -oUser -cConsole Main : Insert code here }
  DataModule2 := TDataModule2.Create( nil );
  try
    DataModule2.doit;
    while DataModule2.p.State <> psReady do
    begin
      application.ProcessMessages;
      sleep(1);
    end;
  finally
    DataModule2.free;
  end;
end.

In the Datamodule:

procedure TDataModule2.doit;
begin
  p.CommandLine := 'notepad.exe c:\temp\1.htm';
  p.Run;
end;

procedure TDataModule2.pTerminate(Sender: TObject; ExitCode: Cardinal);
begin
  ShowMessage( 'terminated' ); //this doesn't ever get executed!
end;

Please help guys and gals.
TagsNo tags attached.

Activities

FireStormX

2007-07-09 19:05

reporter   ~0013554

using Delphi 7 on WinXP...

2007-07-09 19:07

 

reproduce.7z (4,857 bytes)

obones

2007-07-10 02:13

administrator   ~0013556

AFAIK, there are no messages for a console application, so the Application.ProcessMessages call should never return.
On top of that, IIRC the OnTerminate event is called via "Synchronize" hence you should call "CheckSynchronize" in your loop.
Let me know if that helps.

FireStormX

2007-07-10 03:40

reporter   ~0013558

Thank you VERY much for the prompt response! Classes.CheckSynchronize() did the trick!

I hear your comment on Application.ProcessMessages, but...if I don't call ProcessMessages and redirect the stdout of the called console app it doesn't show the text when it is written by the application.

I've included the source and binaries (one with the call and one without) of a test application that will show you this. If there is some other function to achieve this, please let me know.

2007-07-10 03:43

 

JvCreateProcessTest_bin.7z (197,453 bytes)

2007-07-10 03:43

 

JvCreateProcessTest_Src.7z (1,252 bytes)

obones

2007-10-12 06:53

administrator   ~0013919

Ah yes, the process message is needed in that case, you are right.
Glad you got this sorted.

Issue History

Date Modified Username Field Change
2007-07-09 19:03 FireStormX New Issue
2007-07-09 19:05 FireStormX Note Added: 0013554
2007-07-09 19:07 FireStormX File Added: reproduce.7z
2007-07-10 02:13 obones Note Added: 0013556
2007-07-10 02:13 obones Status new => feedback
2007-07-10 03:40 FireStormX Note Added: 0013558
2007-07-10 03:43 FireStormX File Added: JvCreateProcessTest_bin.7z
2007-07-10 03:43 FireStormX File Added: JvCreateProcessTest_Src.7z
2007-10-12 06:53 obones Status feedback => resolved
2007-10-12 06:53 obones Resolution open => no change required
2007-10-12 06:53 obones Assigned To => obones
2007-10-12 06:53 obones Note Added: 0013919