Solved

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

Posted on 2001-07-01
18
162 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
add combobox item based on numbers 9 154
Convert GUI app into console app for Win32 Env 5 112
creating threads in delphi 1 138
TEMBEDDEDWB how can i change its user agent ? 8 70
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…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

808 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