Board index » delphi » BUG: halt() doesn't seem to work

BUG: halt() doesn't seem to work

Try this extremely simple test.  Construct an app with just
a single form and a single button.  Implement a method for
the OnClick event.  Have it just call
        halt(1);

This is documented as terminating the app and returning the
numeric argument as an exit code.  However, the exit code is
always zero.  You can test this by running the app from a
dos shell, and testing the exit code like so:

        testhalt.exe
        if errorlevel 0 echo exit status 0

Sounds like a bug to me.

luke

Actually, you'd probably need a little batch file to test
this properly:

        tester testhalt.exe

tester:

@echo off
%1 %2 %3 %4 %5 %6
if errorlevel 1 goto failed
        echo %1 okay
        goto done
:failed
        echo %1 failed
:done

And note that builtin commands don't set the errorlevel,
if you're testing the `tester' batch file itself.
Sheesh.

 

Re:BUG: halt() doesn't seem to work


Quote
>Try this extremely simple test.  Construct an app with just
>a single form and a single button.  Implement a method for
>the OnClick event.  Have it just call
>    halt(1);

>This is documented as terminating the app and returning the
>numeric argument as an exit code.  However, the exit code is
>always zero.  You can test this by running the app from a
>dos shell, and testing the exit code like so:

>    testhalt.exe
>    if errorlevel 0 echo exit status 0

>Sounds like a bug to me.

1. You can't run a Delphi app in DOS, so I'm curious as to how you managed
this.

2. You are misunderstand how errorlevels, and specifically 'if errorlevel,'
works in MS-DOS.  What it does is tell you whether the errorleve is equal to
OR ABOVE the specified number.  So you have to test the highest possible
errorlevel you expect first, then the next-highest, etc.  I wrote a simple TP6
app:

begin
   halt (1);
end.

And tried the following:

if errorlevel 3 echo blah

It did not echo anything.  The errorlevel must be under 3.

if errorlevel 1 echo blah

It echoed blah; the errorlevel is 1 or above (true, as 1 is greater than or
equal to 1).

if errorlevel 0 echo blah

It echoed blah; the errorleve is 0 or above (true, as 1 is greater than or
equal to 0).

Kendall

Re:BUG: halt() doesn't seem to work


Kendall P. Bullen (kend...@his.com) wrote:
: >Try this extremely simple test.  Construct an app with just
: >a single form and a single button.  Implement a method for
: >the OnClick event.  Have it just call
: >  halt(1);
: >
: >This is documented as terminating the app and returning the
: >numeric argument as an exit code.  However, the exit code is
: >always zero.  You can test this by running the app from a
: >dos shell, and testing the exit code like so:
: >
: >  testhalt.exe
: >  if errorlevel 0 echo exit status 0
: >
: >Sounds like a bug to me.

: 1. You can't run a Delphi app in DOS, so I'm curious as to how you managed
: this.

You can with NT (W95 as well ?) :-)

   /Johan...!

Re:BUG: halt() doesn't seem to work


In article <4aohtp$...@sophocles.algonet.se>,
   w...@sophocles.algonet.se (Johan Alveborg) wrote:

Quote
>: 1. You can't run a Delphi app in DOS, so I'm curious as to how you managed
>: this.
>You can with NT (W95 as well ?) :-)

Fascinating, captain.  Wow, I guess they stole that concept from OS/2.  I
suspect that if it doesn't work it's some weirdness with running a 16-bit app
then, or perhaps how it runs apps in general from the command-line (does a
regular TP6 program like I mentioned return correct errorlevels in NT/95? how
about a TPW program?) . . . ?  I'll have to check this out.  ;)

Kendall

Re:BUG: halt() doesn't seem to work


kend...@his.com (Kendall P. Bullen) wrote:

Quote
>>Try this extremely simple test.  Construct an app with just
>>a single form and a single button.  Implement a method for
>>the OnClick event.  Have it just call
>>        halt(1);

>>You can test this by running the app from a
>>dos shell, and testing the exit code like so:

>>        testhalt.exe
>>        if errorlevel 0 echo exit status 0

>>Sounds like a bug to me.
>1. You can't run a Delphi app in DOS, so I'm curious as to how you managed
>this.

He probably is running Win95, which will start a Windows app from a
Dos session properly.  The DOS session starts the Win App, but it does
not wait for the program to terminate.  Thus, the errorlevel would not
be set based upon whether the Win App successfully started or not (if
it gets set at all).

Re:BUG: halt() doesn't seem to work


Quote
degreeAbsolute (deg...@gti.net) wrote:

: kend...@his.com (Kendall P. Bullen) wrote:

: >>Try this extremely simple test.  Construct an app with just
: >>a single form and a single button.  Implement a method for
: >>the OnClick event.  Have it just call
: >>      halt(1);
: >>

: >>You can test this by running the app from a
: >>dos shell, and testing the exit code like so:
: >>
: >>      testhalt.exe
: >>      if errorlevel 0 echo exit status 0
: >>
: >>Sounds like a bug to me.

: >1. You can't run a Delphi app in DOS, so I'm curious as to how you managed
: >this.
: He probably is running Win95, which will start a Windows app from a
: Dos session properly.  The DOS session starts the Win App, but it does
: not wait for the program to terminate.  Thus, the errorlevel would not
: be set based upon whether the Win App successfully started or not (if
: it gets set at all).

In NT the DOS box waits for the Windows-app to close before being
activated again. Perhaps this is configurable.

   /Johan...!

Other Threads