Ich habs jetzt anders. So wollte ichs eigentlich lassen. Soll so eine Art dynamischer Timer sein (Basiert auf DeddyH’s TWaitCounter).
Delphi-Quellcode:
TWaitCounterEx = class
private
FStart, FStop, FFrequency: Int64;
FStartTime, FStopTime, FWaitTime: double;
FSuccess: boolean;
function GetCanWaitTimer: boolean;
public
procedure Start;
procedure Stop;
property WaitTime: double read FWaitTime;
property CanWaitTimer: boolean read GetCanWaitTimer;
constructor Create;
end;
..
{ TWaitCounterEx }
constructor TWaitCounterEx.Create;
begin
FSuccess := QueryPerformanceFrequency(FFrequency);
end;
procedure TWaitCounterEx.Start;
begin
if FSuccess and QueryPerformanceCounter(FStart) then
FStartTime := FStart / FFrequency;
end;
procedure TWaitCounterEx.Stop;
begin
if FSuccess and QueryPerformanceCounter(FStop) then
begin
FStopTime := FStop / FFrequency;
FWaitTime := (FStop - FStart) / FFrequency;
end;
end;
function TWaitCounterEx.GetCanWaitTimer: boolean;
begin
// NewStartTime - OldStopTime >= OldWaitTime;
Result := not FSuccess or (CompareValue(FStartTime - FStopTime, FWaitTime, 1E-8) >= 0);
end;
(*
procedure TSomeForm.PaintBoxMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
FWaitCounter.Start;
try
if FWaitCounter.CanWaitTimer then
begin
..
end;
finally
FWaitCounter.Stop;
end;
end;
*)