Board index » delphi » "modally" launching a new instance

"modally" launching a new instance

2005-03-05 09:32:16 AM
Sorry if this is not the right place for this, I am not really sure what the
right newsgroup is because I am not quite sure of the best way to implement
the feature I want!
I need an instance of my program to launch another instance of the same
program, while the child instance is running the parent instance needs to be
disabled, i.e. I am effectively trying to get the child instance to launch
modally. Is this possible and what's the best way of doing it?
James Holt

Re:"modally" launching a new instance

I use the following(in D7) to do what it sounds like you want. The launching app just sits there waiting for the launched app to close before continuing.
{ Execute an external application APPNAME.
Pass optional parameters in PARAMS, separated by spaces.
Wait for completion of the application
Returns FALSE if application failed. }
function ExecAppWait(AppName, Params: string): Boolean;
// Structure containing and receiving info about
// application to start
ShellExInfo: TShellExecuteInfo;
FillChar(ShellExInfo, SizeOf(ShellExInfo), 0);
with ShellExInfo do begin
cbSize := SizeOf(ShellExInfo);
fMask := see_Mask_NoCloseProcess;
Wnd := Application.Handle;
lpFile := PChar(AppName);
lpParameters := PChar(Params);
nShow := sw_ShowNormal;
Result := ShellExecuteEx(@ShellExInfo);
if Result then
while WaitForSingleObject(ShellExInfo.HProcess, 100) = WAIT_TIMEOUT do
if Application.Terminated then Break;
hope it helps, let me know if you'd like an eg.