I.T. Discussion Community!
-Collapse +Expand
Delphi
Search Delphi Group:

Advanced
-Collapse +Expand Delphi To/From
To/FromCODEGuides
-Collapse +Expand Delphi Store
PRESTWOODSTORE

Prestwood eMagazine

September Edition
Subscribe now! It's Free!
Enter your email:

   ► MB LobbyPascal and Delphi Coding BoardDelphi Object PASCAL Topic   Print This     

Break a loop

Break a loop in Delphi Object PASCAL topic (part of our Pascal and Delphi Coding group).

Quick Search: Break loop  
dibefog
italy

Can i terminate a (long) for,while,repeat loop when i'm tired to waiting for the end ,with a click on a button?

And can i resume it after?

thank you!!

 Posted 16 years ago (Thread Starter)
Comment Quote
About dibefog -Collapse +Expand
Visit Profile
Membership pending.
Member subscribes to this thread but email is NOT VERIFIED.
Email Not Verified!
Once email is verified, we will review and approve the account.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html, social networking links, message board signature, company profile, etc.

Post ID #9368, 4 replies
Thread Started 4/5/2003 8:07:00 AM
View Counter=4241
Last Reply Posted 4/10/2003 12:54:00 AM)
Location=italy  
Joined=17 years ago   MB Posts=9  
Most Recent Post
NevilleRichards
 (Inactive)
UK
A simple way of breaking-out of a long loop would be to have a pause button which sets a boolean pause variable, and include a test for that pause variable in the while loop (given one of the instructions which enables things to work while the loop is in progress).
 Posted 16 years ago
Comment Quote
About NevilleRichards -Collapse +Expand
Visit Profile
Inactive member.
Member does not subscribe to this thread.
Old Account!
If this is your account, sign in to activate web presence data (sign in quarterly to keep active). Alternatively, you can subscribe to our monthly eMag with a valid email address.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html, social networking links, message board signature, company profile, etc.

Post ID #9389 (Level 1.1)  Reply to 9368
Thread Started 4/10/2003 12:54:00 AM
View Counter=2
Location=UK  
Joined=18 years ago   MB Posts=41  
Angel
 (Inactive)
England
The simple answer is no. If you were to write several long procedures and assign them all to a series of button clicks, you would notice that after clicking the first button, the system would not respond until after it has finished its procedure. If you had clicked the second button in this time, it would then carry out the second procedure and so on... Yikes!

What you want to do could be accomplished by using threads. A thread will basically perform your looped procedure but leave the program "unlocked" so that you can carry out other commands like, for example, a cancel. Think!

Check the helpfile for info on threads and if you get stuck, come back again and somebody will surely help you out. :)
 Posted 16 years ago
Comment Quote
About Angel -Collapse +Expand
Visit Profile
Inactive member.
Member does not subscribe to this thread.
Email Not Verified!
Once email is verified, we will review and approve the account.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html, social networking links, message board signature, company profile, etc.

Post ID #9372 (Level 1.2)  Reply to 9368
Reply Posted 4/7/2003 2:33:00 AM
Location=England  
Joined=18 years ago   MB Posts=199  
dibefog
italy
i'm tryed with a timer, it runs and i can pause it but it's too slow!!! Confused Confused
 Posted 16 years ago (Thread Starter)
Comment Quote
About dibefog -Collapse +Expand
Visit Profile
Membership pending.
Member subscribes to this thread but email is NOT VERIFIED.
Email Not Verified!
Once email is verified, we will review and approve the account.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html, social networking links, message board signature, company profile, etc.

Post ID #9373 (Level 1.3)  Reply to 9368
Reply Posted 4/7/2003 6:34:00 AM
Location=italy  
Joined=17 years ago   MB Posts=9  
Scott Wehrly
Prestwood IT
 (Inactive)
Las Vegas, NV USA
Ah, I can see this evolving into a lengthy thread on Threads and Timers... Think!



dibefog, what does your system performance look like when you are running this while loop routine? Do you see your CPU usage spike?



If it takes a long time to respond, it's probably due to the fact that your application isn't freeing up the CPU cycles necessary for intercepting Windows messages (i.e. button clicks). Angel is right...procedures remain running until they terminate...or something interrupts them.



First, try adding this line to your while loop:

 Sleep(500);


This frees up CPU cycles long enough for the Windows event handler to get a message sent.



Second (if that doesn't solve the problem), change the line to:

 Application.ProcessMessages;


This has the same result, but for a different reason. This interrupts your loop long enough for the application to process other Windows events (like an OnClick event).



For my money, though, TTimers are best used for synchronous waits...like socket connection responses...to indicate timeout conditions. For infinite loop logic like this, Threads are a better solution, because they run "independent" of the application process and allow Windows events to get through (I'm sure I'll be debated on the use of "independent", but I'm just trying to simplify the model).
 Posted 16 years ago
Comment Quote
About Scott Wehrly -Collapse +Expand
Visit Profile
Inactive member.
Member does not subscribe to this thread.
Old Account!
If this is your account, sign in to activate web presence data (sign in quarterly to keep active). Alternatively, you can subscribe to our monthly eMag with a valid email address.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html, social networking links, message board signature, company profile, etc.

Post ID #9376 (Level 1.4)  Reply to 9368
Reply Posted 4/7/2003 7:02:00 AM
Location=Las Vegas, NV USA 
Joined=17 years ago   MB Posts=442   KB Posts=19  

Revive Thread!

Add a comment to revive this old thread and make this archived thread more useful.

Write a Comment...
Full Editor
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1151A1
Enter key:
Icon: A Post    Thread    Idea    Important!    Cool    Sad    No    Yes    Includes a Link...   
Thread #9368 Counter
4241
Since 4/2/2008

Regarding...

Linked Knowledge Base Article.

This thread is linked to the following KB article.


Mike Prestwood
1. Looping in ObjectPAL

Using loop structures in ObjectPAL (for, forEach, scan, while, and looping with timers).

Posted to KB Topic: OPAL: Language Details
11 years ago, and updated 10 years ago
(1 KB Comments)

Article
Nothing New Since Your Last Visit
15462
Hits

Corel Paradox / ObjectPAL Coding


Follow PrestwoodBoards on: 


©1995-2019 PrestwoodBoards  [Security & Privacy]
Professional IT Services: Coding | Websites | Computer Tech