Solved

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

Posted on 2001-07-01
18
163 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

740 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