Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Delphi events and processing

Posted on 2001-06-22
1
Medium Priority
?
255 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 300 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

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…
Loops Section Overview
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

886 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