Our Delphi project can be built directly from the IDE, of course. But launching from the command line allows the process of building multiple projects to be automated. We are using:
ShellExecute(0,
'open',
PChar('[PATH-TO-DELPHI]\Bin\DCC32.EXE'),
PChar('-B [PATH-TO-PROJECT]\MyProject.dpr'),
PChar('[PATH-TO-PROJECT]'),
SW_HIDE);
Normally this works great when there are no code or build errors, and ShellExecute
returns a value of "42". However, if there are build errors, the return value is still "42".
You could build the project in the IDE to find the error(s). But is it possible to detect compilation errors from the command line, or to check some file or log to see if the build was successful or not?
Best Answer
Use
CreateProcess()
(orShellExecuteEx()
) instead ofShellExecute()
. That way, you can get aHANDLE
to the process, then useWaitForSingleObject()
to wait for the process to end, and finally get its exit code withGetExitCodeProcess()
.