A netizen raised the following question: how to give the Delphi application a return code, similar to C's exit (-1)
The result is as follows:
The Processing Method of Delphi is somewhat different from that of C/C ++. in Delphi, the processing of parameters and return values for main or winmain functions is through system. some corresponding variables and functions in PAS are implemented.
The Return Value of the program is defined in exitcode in system. Pas.
Therefore, to set the return value of a program to 1, you only need to set exitcode: = 1; in the program.
The following test code:
program Project2;{$APPTYPE CONSOLE}uses SysUtils;begin ExitCode :=10 ;end.
Test. bat
@ Echo offrem test1.exe is a program written using the CEN certificate. the return value is 33test1.exe echo test1.exe return % errorlevel % REM project2.exe, which is the code on the top. project2.exe echo project2.exe return % errorlevel %
Execution result:
test1.exe return 33project2.exe return 10
Note:
I have not studied this before, but after seeing the problem, I feel that Delphi should be able to solve it. Therefore, use the debug tool for tracking as follows:
00403595 |. FF15 24904000 |call dword ptr ds:[409024]0040359B |> 8B06 |mov eax,dword ptr ds:[esi]0040359D |. 50 |push eax ; /ExitCode0040359E |. E8 EDDAFFFF |call <jmp.&kernel32.ExitProcess> ; \ExitProcess
Therefore, the Delphi Program has a global variable: DS [esi]
In fact, this variable is exitcode.