Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Fast delay function for delphi

608 views
Skip to first unread message

Peter Uhd Jepsen

unread,
May 11, 2000, 3:00:00 AM5/11/00
to
Hello Delphi people:

I have the following problem: I need a way to make my delphi 3 program
wait
x microseconds before continuing with the next operation, similar to the
borland
command delay(n) where n of course is in milliseconds, not micros.

Does any of you know a way of timing delphi programs in this way ?

Thank you very much in advance,
Peter.

--
--------------------------------------------------------------
Dr. Peter Uhd Jepsen
Department of Molecular and Optical Physics
University of Freiburg
Hermann-Herder-Str. 3
D-79104 Freiburg
email: jep...@uni-freiburg.de
www: http://frhewww.physik.uni-freiburg.de/~puhd/homepage
--------------------------------------------------------------

Conor Boyd

unread,
May 11, 2000, 3:00:00 AM5/11/00
to
Afraid I'm not familiar with delay(n), but would the
Windows.Sleep(milliseconds) function not do what you want?

HTH,

Conor

Peter Uhd Jepsen <jep...@uni-freiburg.de> wrote in message
news:391AA98E...@uni-freiburg.de...

James Redmahura

unread,
May 12, 2000, 3:00:00 AM5/12/00
to
Windows does not provide microseconds based
delay function. You must write your own code.
QueryPerformanceCounter would be proper API
function. you can implement the delay function
by using busy waiting as below. (pseudo)

procedure microdelay(amount)
begin
lasttick := QueryPerformanceCounter;
while(QueryPerformanceCounter < lasttick + amount) do ;
end;

but the important fact is that above function
is based on busy waiting and so it blocks
other processes from taking the CPU time.

Otherwise when you call Win32 Sleep API function,
OS preempts your process(current calling process)
and give CPU time to other waiting process.

It is very difficult to develop microseconds or even
miliseconds based time-critical applications on
Windows 98/NT, because its target is not realtime
OS.

you can get more detailed information from MSDN library.

bye

R.Kleefstra

unread,
May 12, 2000, 3:00:00 AM5/12/00
to
You might try to use assembler-code.

Find out the speed of the current processor. (from the registry?)
Calculate the number of operations (cycles) it can do within a millisecond.
600mhz -> 600,000,000 oper/sec?
then create a loop something like this (it has been a while since I used
assembler...)

maxloop := mhz / 2
asm
di //disable interrupts (dangerous)
mov EAX, maxloop
@start
dec EAX //needs 1 cycle
jnz start //needs 1 cycle
ei //enable interrupts
end

I think the timing will be loosy, but it's a start...

"Peter Uhd Jepsen" <jep...@uni-freiburg.de> wrote in message
news:391AA98E...@uni-freiburg.de...


> Hello Delphi people:
>
> I have the following problem: I need a way to make my delphi 3 program
> wait
> x microseconds before continuing with the next operation, similar to the
> borland
> command delay(n) where n of course is in milliseconds, not micros.
>
> Does any of you know a way of timing delphi programs in this way ?
>
> Thank you very much in advance,
> Peter.
>

Conor Boyd

unread,
May 12, 2000, 3:00:00 AM5/12/00
to
Oops, sorry, reading the other posts made me realise I completely
misunderstood the original post. My apologies...

Conor

Conor Boyd <conor....@nospam.zonal.co.uk> wrote in message
news:yZAS4.1832$vg5.2...@news3.cableinet.net...


> Afraid I'm not familiar with delay(n), but would the
> Windows.Sleep(milliseconds) function not do what you want?
>
> HTH,
>
> Conor
>

Peter Uhd Jepsen

unread,
May 15, 2000, 3:00:00 AM5/15/00
to
Hello,

Thank you for the answers, I'll try out the options...

0 new messages