Jump to content

Pause or Canecel execution


SergioFeitoza

Recommended Posts

Hi. Suppose I have a code running and doing a calculation that take some time.

What should I include in the event of a “PAUSE” uniButton if I wanted to pause  the execution and , if clicking again, to re-start the execution ?

And, if the button is a STOP EXECUTION, what should I include ?

Thanks in advance

Link to comment
Share on other sites

Hi Sherzod

Just to serve as an example suppose  that I have a simple  loop like below and I click a button to start the calculation of Z  but , it takes more than lets say 1 second I want to Stop or to Pause clicking another button

 

LongCalculation(Sender: TObject);

begin

x:=1;

y:= 2;

while Z < 10000000000000000 do

begin

 Z := X + Y;

X := X +0.1;

Y := Y + 0.1;

End;

 

Today, in VCL  I do like this to stop the loop. Maybe there is something simpler:

…….

CancelExecution:= false;

for ptsTime := 1 to ptsTimeMax

 try

 while ptsTime <=ptsTimeMax do

   begin

         try

           while ptsTime <=ptsTimeMax do

          begin

                Application.ProcessMessages;  

                if CancelarExecucao then   

                    begin

                    ShowMessage ('Operation cancelled by the user.');

                    Break;                       // Sai do loop

                    end;

    end;

          Finally

             formCancelExecution.Close;

         end;

/////////////////////////

procedure TformCancelExecution.BTNCancelExecutionClick(Sender: TObject);

    begin

      F0D.CancelaExecution := true;

    end;

Link to comment
Share on other sites

On 4/20/2020 at 11:50 PM, SergioFeitoza said:

LongCalculation(Sender: TObject);

begin

x:=1;

y:= 2;

while Z < 10000000000000000 do

begin

 Z := X + Y;

X := X +0.1;

Y := Y + 0.1;

End;

Today, in VCL  I do like this to stop the loop. Maybe there is something simpler:

…….

CancelExecution:= false;

 //--> Show Panel here, panel aling client

for ptsTime := 1 to ptsTimeMax

 try

 while ptsTime <=ptsTimeMax do

   begin

         try

           while ptsTime <=ptsTimeMax do

          begin

                Application.ProcessMessages;  

                if CancelarExecucao then   

                    begin

                    ShowMessage ('Operation cancelled by the user.');

                    Break;                       // Sai do loop

                    end;

    end;

          Finally

             formCancelExecution.Close;

// --> Hide Panel here

         end;

 

/////////////////////////

// --> This button be on Panel

procedure TformCancelExecution.BTNCancelExecutionClick(Sender: TObject);

    begin

      F0D.CancelaExecution := true;

    end;

When show Panel, and its Alignment is Client, and it has a cancel button. EndUser have to click & break loop or have to wait finish loop

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...