Solved

Calling a function continuously

Posted on 1998-05-06
2
154 Views
Last Modified: 2010-04-06
I wrote a function that moves an object across a form and bounces off the edges.. (each time the function is called, the object moves 2 pixels in a specified direction, if that movement causes it to exceed the edge of the form, I change the direction and move away from the edge)

How do I keep calling this function as long as my Form exist.

I want the object to keep moving around until I change a variable (by pressing a button)... I also want to be able to do other operations on this form  (press other buttons...) without stopping the movement of my object?

Any ideas??
0
Comment
Question by:rafy
2 Comments
 
LVL 5

Accepted Solution

by:
JimBob091197 earned 100 total points
ID: 1342523
Hi

There are several ways of doing this.  By far the quickest is to add a TTimer to your form (TTimer is on System tab on Delphi's component palette).  Set the TTimer's interval to number of milliseconds (e.g. 500 for half sec) and program the OnTimer event.  This shouldn't interfere with the rest of your program.

Another method is to create a thread to handle the movement of your object.  This would require more work, but if you want to investigate it, look up TThread in Delphi.

Cheers,
JB
0
 

Author Comment

by:rafy
ID: 1342524
The timer works great as long as the other event is discrete like a button press, but it still stops (even the timer) when the event is something like onmousemove where I do something else as long as the mouse is located on my button.  This suspends the timer (and the bounce) until I move my mouse away from the button.

Oh well, Threads it is!
Thanks
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question