Board index » delphi » Help needed (running a program from a program).

Help needed (running a program from a program).

I have been working on this for a while, and cannot figure it out.  I
am writing this program that calls another application, and when it
is finished, it needs to return to the main menu.  

The problem is, is that when it gets to the part that runs the
program, the program is not run.  It simply returns to the menu.

Code available upon request.

Ben Doyle
bdo...@acad.cc.whecn.edu

 

Re:Help needed (running a program from a program).


Quote
>I have been working on this for a while, and cannot figure it out.  I
>am writing this program that calls another application, and when it
>is finished, it needs to return to the main menu.  

>The problem is, is that when it gets to the part that runs the
>program, the program is not run.  It simply returns to the menu.

>Code available upon request.

>Ben Doyle
>bdo...@acad.cc.whecn.edu

Ok. What you need to do is this:

{ Example for DosExitCode and Exec }

 {$M $4000,0,0 }   { 16K stack, no heap }
 uses Dos;
 var
   ProgramName, CmdLine: string;
 begin
   Write('Program to Exec (full path): ');
   ReadLn(ProgramName);
   Write('Command line to pass to ',
         ProgramName, ': ');
   ReadLn(CmdLine);
   WriteLn('About to Exec...');
   SwapVectors;
   Exec(ProgramName, CmdLine);
   SwapVectors;
   WriteLn('...back from Exec');
   if DosError <> 0 then{ Error? }
     WriteLn('Dos error #', DosError)
   else
     WriteLn('Exec successful. ',

             'Child process exit code = ',
             DosExitCode);
 end.

BTW, this example came from the help file. The important thing to note is the
{$M $4000, 0, 0}. This restricts the amount of memory that is allocated to the
program when run. Normally, DOS allocates ALL available memory to the program.
When you try to Exec your other program, there is no memory to run it in.

--------------------------------------------------------
 Robert Vandervelde  + ...that what we have learned and
 RV...@snowhill.com  +  truly understood, we discovered
 Enterprise, AL      +  ourselves.                      
 The Wiregrass       +      - Richard C. Dorf          
--------------------------------------------------------

Other Threads