Search code examples
delphi

ShellExecute not working from IDE but works otherwise


I want to create and then open a txt file using the ShellExecute command.

I have used this code for years with Delphi 7 and it worked:

function Execute(CONST ExeName, Parameters: string): Boolean;
begin
 Result:= ShellExecute(0, 'open', PChar(ExeName), PChar(Parameters), nil, SW_SHOWNORMAL)> 32;
end;

Now, I switched to Windows 7 and the code is not working anymore when it runs from IDE. Delphi shows the CPU window with the caption "CPU-Process unknown (2352)". I close the CU windows and everything works fine until I close the application, when Delphi shows the CPU window one more time. If I run the app from outside IDE, it works fine.

Looks like the debugger has something to say to me, but I don't know what.


Solution

  • Sounds to me like you have the "debug spawned processes" option turned on. When that's enabled, the debugger interrupts the new process at the earliest possible time. Press the "run" button to let it continue running.

    You can confirm this hypothesis the next time you debug your program. Compare the process ID (2352, in your example) with the list of processes shown by Task Manager. Which process in that list matches the process ID reported by the debugger?