Solved

Calling a function continuously

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

863 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now