Solved

Delphi events and processing

Posted on 2001-06-22
1
244 Views
Last Modified: 2010-04-06
What is the outcome when there are 2 different events calling the same procedure? will the procedure be pre-empted or will delphi create another instance of that procedure?

given:
 * 2 timers - TimerA and TimerB both enabled at the same time with the same time interval
 * 1 common procedure - Procedure Process_Data(code: string); (doing some lengthy processing)
    if code=A then process with parameter A
    if code=B then process with parameter B

sequence of events:
 * enable TimerA and TimerB
 * OnTimer of TimerA - call Process_Data('A');
   OnTimer of TimerB - call Process_Data('B');

how is the procedure going to proceed? will there be time-slicing? and if so, what are the priorities?
0
Comment
Question by:ttanyag
1 Comment
 
LVL 20

Accepted Solution

by:
Madshi earned 100 total points
ID: 6217588
Windows timers work via messages. That means, as long as you don't handle messages, no timer is fired. That again means, if the first timer is fired, your callback function is called. If you don't do any message handling in this function, the second timer has to wait (even if the time is over), until your callback function is run through. Only then (hopefully someone else now handles messages, e.g. Application.Run does) the second timer is finally fired.

Delphi doesn't copy a procedure "instance" or code. If you create 2 timers that share the same callback function, then the same function is called. However, if you use Delphi's TTimer object (instead of pure win32 API), you can use "Self" to differ between the different parent timers.

Time slicing only applies to threads. Timers are no threads. One after the other is the mode, except if you're handling messages in the timer callback function, then the second timer may be fired, while the first is not fully handled yet. But then the first timer is "paused" as long as the 2nd is not finished.

Regards, Madshi.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
FMX enumerated colours 2 73
Run video youtube webbrowse 10 45
Delphi inherited method 6 42
JAudiorecorder record freezing the app 30 37
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

744 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

13 Experts available now in Live!

Get 1:1 Help Now