Link to home
Start Free TrialLog in
Avatar of pipinana2002
pipinana2002

asked on

Call Delphi Program from another Delphi program

Hi all..

Let's say I have 2 Delphi programs.. just call it Father and Son.

Father has 50 statements and Son has 10 statements to execute when they are called/runned.

If first we run Father, at statement no 20, Father will call Son. When this happens, Son will execute his 10 statements. I want to make it such that: the Father will only continue to run his statements (statement 21 - 50) AFTER Son has finished executing his 10 statements. So it's like Father will wait until the Son finishes his statements then the Father will continue his statements.

Is there any way I can do this? I think for calling another delphi program, we have to use winexec is it?

Thankss for your help :)
Avatar of mokule
mokule
Flag of Poland image

Better use CreateProcess for this purpose

procedure ExecExtern;
const
  MAXTIME=5000;           // max wait 5 seconds
var
  tp,tk: dword;
  exitcode: dword;
  procinf: PROCESS_INFORMATION;
  stinfo: STARTUPINFO;
begin
      GetStartupInfo(stinfo);
// if You want to show Son
      stinfo.wShowWindow := SW_SHOW
// if You want to hide Son
      stinfo.wShowWindow := SW_HIDE;
// start son
      CreateProcess(nil,PChar('YourSon.exe'),nil,nil,FALSE,0,nil,nil,stinfo,procinf);
// waiting for Son end not more then MAXTIME
      tp := GetTickCount;
      while tp + MAXTIME > GetTickCount do
          begin
//          Application.ProcessMessages;
          if not GetExitCodeProcess(procinf.hProcess,exitcode) then
            break;
          if exitcode <> STILL_ACTIVE then
            break;
          end;
end;
ASKER CERTIFIED SOLUTION
Avatar of TomGrills
TomGrills

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TomGrills
TomGrills

you really don't need the tmpFileName variable in my example...  I modified some old code I had.....
Avatar of pipinana2002

ASKER

Hi all..

Thank you for all your answer.. I will test the code first and I'll get back to u :) Thanksssss...
Is the a reason for Son to be a exe? If not why not make Son a dll. Then simply call it at line 20.
I wrote a IPC components designed to allow InterProcess Communications between to processes
try this link at torrys  http://www.torry.net/vcl/system/appcommunications/bmipc.zip

What I used it for in the past was to send a message to another one of my apps to do something.
So what you could do is have the father wait until the son sends a message to continue on with the rest of the process

Bill
HI all.. thanks for all your answer, especially to TomGrills.. hehehe I finally can make i work ;)