Solved

Calling a function continuously

Posted on 1998-05-06
2
155 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

808 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