Link to home
Start Free TrialLog in
Avatar of Hardi
Hardi

asked on

Need advice about ExecAndWait, or the global var Application

I have been using this function to execute an external application and wait until it finishes before executing the next line
http://delphi.about.com/od/windowsshellapi/a/executeprogram.htmĀ (scroll down)
It's perfect.

But now because I use it in a number of applications, I am thinking of putting this function into a new unit, so I can just include this unit in each application rather than copy-pasting the whole code.
However it involves Application global variable, should I include Forms in my unit? Or is there a more suitable function to be put in a separate unit?

(I need the function to wait until the external app finishes before executing the next line, and can take arguments for running the external app)

Thank you in advance
Avatar of Lukasz Zielinski
Lukasz Zielinski
Flag of Poland image

you can always pass Application as param to this function:)

ziolko.
Avatar of Hardi
Hardi

ASKER

I know... so I have to include Forms in my unit?
Is there any better solutions? Like changing the function so it doesn't use Application?

Because in a console application, including Forms can increase the filesize a lot... right now I'm only using it in windows applications though...
yes, you need to add Forms to new unit.

however if you want to avoid using Application (which requires forms) it's possible with CreateProcess() and one of waiting functions (like WaitForMultipleObjects)

ziolko.
ASKER CERTIFIED SOLUTION
Avatar of Lukasz Zielinski
Lukasz Zielinski
Flag of Poland image

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 Hardi

ASKER

It works, thank you ziolko! It's robust isn't it?
So in your opinion, which one is better to be put into a new unit?
well it depends, in console app CreateProcess and WaitForSingleObject for sure is better
also when you need you're app to freeze until created process finishes its execution.

but in case you want you're app to be working and only be notified when launched process exited
you can use method you found on delphi.about, but personally i don't like anything that has loop
with Application.ProcessMessages

ziolko.
Avatar of Hardi

ASKER

Yup me neither, okay I'll use your code. Thanks very much! :-D
glad i could help:)

ziolko.