Solved

Getting the time of a dblClick (1000 points for quick good answer)

Posted on 2001-07-01
18
159 Views
Last Modified: 2010-08-05
hi need your help !!!


i need get the time of a dblclick with accuracy of
 1 millisecond how i do it ?


Igor.
0
Comment
Question by:igor84
  • 6
  • 6
  • 2
  • +4
18 Comments
 
LVL 13

Expert Comment

by:Epsylon
ID: 6242460
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  TForm1 = class(TForm)
    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    { Private declarations }
    lasttime: Cardinal;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var thistime: Cardinal;
begin
  thistime := GetTickCount;
  if thistime - lasttime < GetDoubleClickTime then
    Caption := IntToStr(thistime - lasttime)
  else
    Caption := 'to slow';
  lasttime := thistime;
end;

end.
0
 

Author Comment

by:igor84
ID: 6242466
this function is to slow it gets upto 5 millisec i need upto 1 millisec  sorry ...
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6242481
Doesn't that depend on the CPU speed...?
Here it is fast enough:


procedure TForm1.Button1Click(Sender: TObject);
begin
  Perform(WM_LBUTTONDOWN, 0, 0);
  Perform(WM_LBUTTONDOWN, 0, 0);
end;


When I press button1, it shows 1 in the caption...
0
 
LVL 5

Accepted Solution

by:
alanwhincup earned 100 total points
ID: 6242484
Try this:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  Start : DWord;
  FirstClick, SecClick : Boolean;

implementation

function timeGetTime : DWord; external 'WINMM.DLL';

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
  FirstClick := True;
  SecClick := False;
  Label1.Caption := '0';
end;

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if FirstClick = True then
  begin
    Label1.Caption := '0';
    FirstClick := False;
    Start := timeGetTime;
  end
  else
    SecClick := True;
end;

procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if timeGetTime - Start > GetDoubleClickTime then
  begin
    Label1.Caption := 'To Slow';
    FirstClick := True;
    SecClick := False;
  end
  else
  begin
    if SecClick = True then
    begin
      Label1.Caption := IntToStr(timeGetTime - Start);
      FirstClick := True;
      SecClick := False;
    end;
  end;
end;

end.

Its got a percision of 1 ms because it uses the multimedia timer api timeGetTime in WinMM.dll

Cheers,

Alan
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6242490
Correction: it returns 0 on a 450 MHz CPU...
0
 

Author Comment

by:igor84
ID: 6242554
i found an answer by my self
0
 
LVL 6

Expert Comment

by:edey
ID: 6242583
then you should post it.  It's considered rather rude to solicit help, then delete the q after it's been given.  

GL
Mike
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6242731
> i found an answer by my self

Who says that you didn't use my code....
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6242945
listening . . .
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 6243715
Epsylon: Lock the question to prevent it being deleted.
0
 

Expert Comment

by:bullen
ID: 6243774
Use the PerformanceCounter insted of Ticks.

QueryPerformanceCounter and
QueryPerformanceFrequnecy and

Bullen
0
 

Author Comment

by:igor84
ID: 6243843
i found an answer by myself but because some one posted a right answer he deserves the points, and the right answer is from : alanwhincup.

0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6243863
And what about those promised 1000 points?
0
 

Author Comment

by:igor84
ID: 6243889
because this solution is not the best and don't realy works on 1 millisec accuracy.

if you posted me a solution like this i would give you 1000 points. i realy don't understand you all obsession to points you all are so greedy ?!

p.s you first solution was at accuracy of 5 millisec so ...

Igor
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6243954
Why did you delete the question without explanation? Doesn't that mean that you are greedy for answers?
And why didn't you wait for a better solution instead of deleting it?

Look, this point system increases the response time greatly. There is a certain level of competition between experts, and... they are points, not dollars. I and others spent time trying to help you. I don't even see a 'thank you' or something like that.

Promising 1000 points and then deleting the question without explanation, after you received 2 solutions, is really frustrating. It is NOT DONE!

Eps. (really pissed!)
0
 

Author Comment

by:igor84
ID: 6244164
i deleted by mistake and like you see after that i accepted alanwhincup answer ! and gave him 100 pts (the question value) but if there were good enghot solution like i asked i would give 1000 pts.

i realy thanks you and all other people that are spending theirs time to help others and i realy thank you for that !

p.s don't be angry.

i asked a day before another question that is very thoght and i promiss you the accepted answer will get 1000 points.

p.s from where are you ?
0
 
LVL 5

Expert Comment

by:alanwhincup
ID: 6245661
My solution should give the time to an accuracy of 1ms. It uses a multimedia timer which is implemented using the Win32 multimedia library (winmm.dll). Ive used this instead of any other time because most other timers are limited by the systems resolution.
0
 

Author Comment

by:igor84
ID: 6245943
i agree with you in the help file written that give an accurancy of 1 ms but it isn't like that. i checked it and that disappointmented me. sorry ...
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
IExtractImage Delphi 14 201
FMX enumerated colours 2 84
Connection between libmysql.dll and MySQL Versions 7 87
LAN or WAN ? 11 81
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

914 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now