Board index » delphi » How bad is 'Halt'?

How bad is 'Halt'?

Hi,

The way I'm using Delphi (for teaching 1st yr students Pascal) means that if
the student's program goes into some kind of infinite loop or something,
then a menu option must be selected to terminate the program.

The main form's Close method does not do the job; neither does
Application.Terminate.

Therefore Halt seems to be the only way. But how much resources are lost by
doing this? I call Close and Application.Terminate before calling Halt in
case this will do any good, but I'm still concerned about this way of
aborting a program.....

Any info/advice appreciated!

Iain

Iain Russell
http://www.wintermute.co.uk/users/libra/

 

Re:How bad is 'Halt'?


In <[email protected]>, [email protected] (The Russells) writes:

Quote
>Hi,

>The way I'm using Delphi (for teaching 1st yr students Pascal) means that if
>the student's program goes into some kind of infinite loop or something,
>then a menu option must be selected to terminate the program.

>The main form's Close method does not do the job; neither does
>Application.Terminate.

Hmm.  Could you post some sample code here?  There are two things that can
keep a form from responding to the close request.  Once is setting 'Action' to
'caNone' in the OnClose method.  The other is setting 'CanClose' to 'False' in the
OnCloseQuery method.

Re:How bad is 'Halt'?


Quote
The Russells wrote:

> Hi,

> The way I'm using Delphi (for teaching 1st yr students Pascal) means that if
> the student's program goes into some kind of infinite loop or something,
> then a menu option must be selected to terminate the program.

> The main form's Close method does not do the job; neither does
> Application.Terminate.

> Therefore Halt seems to be the only way. But how much resources are lost by
> doing this? I call Close and Application.Terminate before calling Halt in
> case this will do any good, but I'm still concerned about this way of
> aborting a program.....

        ??? How are you getting Halt to work? It seems like you must
be including an Application.ProcessMessages in the loop or you couldn't
be getting to wherever you execute the Halt statemnt(???). Try this:
instead of saying

while 1=1 do
begin
Application.ProcessMessages;
{do stuff}
end;

say

while 1=1 do
begin
Application.ProcessMessages;
if Application.Terminated then break;
{do stuff}
end;

        Now a simple Application.Terminate should do: that sets Terminated
to True, and then the conditional above breaks out of the loop, tada.

--
David Ullrich
Sig file accidentally deleted - sorry.

Re:How bad is 'Halt'?


Another reason the program may not respond to a request to close the form
is that there are no "application.processmessages" lines in the code.
Sticking one of those in a loop that is being tested will allow you to
break out.

Re:How bad is 'Halt'?


Quote
JefSummers wrote:

> Another reason the program may not respond to a request to close the form
> is that there are no "application.processmessages" lines in the code.
> Sticking one of those in a loop that is being tested will allow you to
> break out.

The original poster made it sound like menu items were selectable while
this funny business is going on (at least that's what it sounded like to
me). If menu items are selectable on a form, messages are being
processed correctly. Application.ProcessMessages would basically do
nothing in that case.

If menu items aren't, in fact, selectable (ie you click on the menu
name and no menu pops up), Application.ProcessMessages is probably the
key.

--Matt
([email protected])

Re:How bad is 'Halt'?


Quote
[email protected] (JefSummers) wrote:
>Another reason the program may not respond to a request to close the form
>is that there are no "application.processmessages" lines in the code.
>Sticking one of those in a loop that is being tested will allow you to
>break out.

Don't worry - I've got *plenty* of Application.ProcessMessages in the
code!  :)

I think the problem is that there is still a program running and due to the
nature of the exercise, this does not have checks in it to see if it should
terminate.

Due to news-server difficulties, I thought this message would not get out,
hence I've posted it again tonight, with further details of what I'm doing.
I hope this will clarify what's going on - I'm abusing Delphi something
rotten  :)

Iain

Iain Russell
http://www.wintermute.co.uk/users/libra/

Re:How bad is 'Halt'?


Quote
David Ullrich <[email protected]> wrote:
>  [snip]

Thanks for the advice - but I've posted a more complete description of what
I'm doing and I hope this will clarify things - this is no normal Delphi
program - it has no Application.Run for a start!  :)

Iain

Iain Russell
http://www.wintermute.co.uk/users/libra/

Other Threads