Delphi program return value

xiaoxiao2021-03-05  21

A netizen puts forward this question: How to give the Delphi application a return code, similar to the EXIT (-1)

After trying, get the result:

Delphi's processing is somewhat different from C / C . Delphi's parameters for Main or WinMain functions and return values ​​are achieved through some corresponding variables and functions in System.PAS.

The return value of the program defines the exitcode in System.PAS. So, if you want the program to return a value of 1, simply set EXITCODE: = 1 in the program;

Test code as follows:

Program Project2;

{$ Apptype console}

Uses sysutils;

Begin {todo -ouser -cconsole main: insert code heren

EXITCODE: = 10;

------ Test for return values: Test.bat

@echo offrem test1.exe is a program written by c , the return value is 33test1.exeecho test1.exe return% Errorlevel%

Rem Project2.exe is the result of the code on the upper side Project2.exe

echo project2.exe return% errorlevel%

@echo on

--------------- Execute: Test1.exe Return 33Project2.exe Return 10

Note: I haven't studied this before, but I feel that Delphi should be solved after seeing the problem of the landlord. So by using the Debug tool, 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 ; / EXIXTPROCESS So Delphi program is a global variable: DS [ESI] In fact, this variable is exitcode.

转载请注明原文地址:https://www.9cbs.com/read-37778.html

New Post(0)