The Delphi IDE obviously sets the system timer tick to a higher resolution. You can do the same in your application by using timeBeginPeriod/timeEndPeriod
functions. See msdn document and also this one regarding sleep function
uses MMSystem;
if TimeBeginPeriod(1) = TIMERR_NOERROR then // 1 ms resolution
try
// The action or process needing higher resolution
finally
TimeEndPeriod(1);
end;
Just to demonstrate the effect I made following simple application, so anybody interested can check for themselves:
uses System.DateUtils, MMSystem;
var
s, e: TTime;
procedure SomeDelay;
var
i: integer;
begin
s := Now;
for i := 1 to 1000 do
Sleep(1);
e := Now;
end;
procedure TForm19.btnWithClick(Sender: TObject);
begin
if TimeBeginPeriod(1) = TIMERR_NOERROR then // 1 ms resolution
try
SomeDelay; // The action or process needing higher resolution
finally
TimeEndPeriod(1);
end;
Memo1.Lines.Add('with ' + IntToStr(SecondsBetween(s, e)));
end;
procedure TForm19.btnWithoutClick(Sender: TObject);
begin
SomeDelay; // The action or process needing higher resolution
Memo1.Lines.Add('without ' + IntToStr(SecondsBetween(s, e)));
end;
Output:
with 1
without 15
NOTE Because the TimeBeginPeriod
affects the system tick, be sure to shut down any program that may us the same method to modify the timer tick, like multimedia and similar programs (and also the Delphi IDE).