Hello
I'm trying change GetTickCount from my codes to QueryPerformanceCounter
code:
Code:
type TCustomTimer = class
private
PerfFrequency: Int64;
InvPerfFrequency: Single;
public
function gettime: Single;
constructor Create;
end;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure Teste(Sender: TObject; var Done: Boolean);
end;
var
Form1: TForm1;
clock: TCustomTimer;
_start, _end: Double;
implementation
{$R *.dfm}
///////////////
{ TCustomTimer }
procedure TForm1.Teste(Sender: TObject; var Done: Boolean);
begin
_end := clock.gettime;
//1000 = frequencia de intervalo em milesegundos
if (_end-_start) >= 1000 then
begin
memo1.Lines.Add('evento');
_start := _end;
end;
end;
constructor TCustomTimer.Create;
begin
QueryPerformanceFrequency(PerfFrequency);
InvPerfFrequency := 1.0 / PerfFrequency;
end;
function TCustomTimer.gettime: Single;
var
Time: Int64;
begin
QueryPerformanceCounter(Time);
Result := 1000 * InvPerfFrequency * Time;
end;
///////////////
procedure TForm1.FormCreate(Sender: TObject);
begin
clock := TCustomTimer.Create;
_start := clock.gettime;
application.OnIdle := Form1.Teste;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
Clock.Free;
end;
my code is ok?
my question...
what is this line?
Code:
InvPerfFrequency := 1.0 / PerfFrequency;
Bookmarks