Delphi program return value

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.