Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2001-07-01
18
Medium Priority
?
170 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
Technology Partners: 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 400 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses
Course of the Month15 days, 8 hours left to enroll

575 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