Board index » delphi » Button to stop processing

Button to stop processing

How do I implement a Cancel button that will stop certain processing
to stop upon the clicking by the user?
 

Re:Button to stop processing


Quote
Chi Tsi wrote:

> How do I implement a Cancel button that will stop certain processing
> to stop upon the clicking by the user?

Use a TSpeedButton. Read about properties Down, AllowAllUp, and
GroupIndex.

--
Bent Tranberg, Agder College, Grimstad
Grooseveien 36, 4890 Grimstad, Norway
e-mail: Bent.Tranb...@hia.no Web: http://www.hia.no

Re:Button to stop processing


I would think that depends on what you're trying to interrupt.

Glen
gm...@haven.ios.com

Quote
Chi Tsi (chi...@pc.jaring.my) wrote:

: How do I implement a Cancel button that will stop certain processing
: to stop upon the clicking by the user?

Re:Button to stop processing


Quote
In article <30D98AD8.4...@hia.no> Bent Tranberg <Bent.Tranb...@hia.no> writes:
>Chi Tsi wrote:

>> How do I implement a Cancel button that will stop certain processing
>> to stop upon the clicking by the user?
>Use a TSpeedButton. Read about properties Down, AllowAllUp, and
>GroupIndex.

Bogus response...  :-{

You need to do the following things:

{1}  Define a boolean flag somewhere called "cancelled."  Set it to false
before you begin processing, and periodically test to see if it has become
true.  If it has, bail out.

{2}  The "onClick" routine of some button -- pick a button -- must set this
flag to true.

{3}  Your code must yield to Windows at regular intervals.  Here is a routine
that I use to do this:

        procedure doEvents;   {sorry.. first name that came to mind ;-}
        begin
           if application.Terminated then abort;
           application.ProcessMessages;
           if application.Terminated then abort;
        end;

/mr/

Re:Button to stop processing


In article <sundial.1855.0028F...@primenet.com>, Sundial Services
<sund...@primenet.com> writes

Quote

>In article <30D98AD8.4...@hia.no> Bent Tranberg <Bent.Tranb...@hia.no> writes:

>>Chi Tsi wrote:

>>> How do I implement a Cancel button that will stop certain processing
>>> to stop upon the clicking by the user?

>>Use a TSpeedButton. Read about properties Down, AllowAllUp, and
>>GroupIndex.

>Bogus response...  :-{

>You need to do the following things:

>{1}  Define a boolean flag somewhere called "cancelled."  Set it to false
>before you begin processing, and periodically test to see if it has become
>true.  If it has, bail out.

>{2}  The "onClick" routine of some button -- pick a button -- must set this
>flag to true.

>{3}  Your code must yield to Windows at regular intervals.  Here is a routine
>that I use to do this:

>       procedure doEvents;   {sorry.. first name that came to mind ;-}
>       begin
>          if application.Terminated then abort;
>          application.ProcessMessages;
>          if application.Terminated then abort;
>       end;

The above is standard and works well, but one word of caution. This
method is best applied to a button on a modal dialog, otherwise you need
to take care of all side effects of possible user actions that can be
performed on the windows/menus/buttons/etc., due to the 'ProcessMessage'
call, which can get very messy.

Normal use is the 'print', 'cancel' button (or a process version of it
as requested), other use may require more thought.

--
Richard Linsley Hood | Poole, Dorset UK | email: richar...@dakal.demon.co.uk
"Programming is mirroring the world, inside a computer"   Larry O'Brien 1991

Turnpike evaluation. For information, see http://www.turnpike.com/

Other Threads