Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Double-Click Without Single

Posted on 2003-11-26
5
Medium Priority
?
357 Views
Last Modified: 2010-04-05
Probably a very easy answer to this one...

I want to do one thing if I click on my memo and another if I double click on it, so I'm using the OnClick and OnDblClick events.

But, it doesn't matter how fast I double click, it only triggers the OnClick event. Any way of stopping this happening?

TDK_Man
0
Comment
Question by:tdk_man
[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
5 Comments
 
LVL 5

Expert Comment

by:snehanshu
ID: 9829663
Well, I thought there would be better solutions than what I could think of, but I couldn't find any in a quick search, so here goes a crude method:

Wait (Sleep) for some time in the onclick event and then see if DoubleClick was done. If not process the single click.
Code:

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    procedure Memo1Click(Sender: TObject);
    procedure Memo1DblClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  IsDouble: Boolean;

implementation

{$R *.dfm}

procedure TForm1.Memo1Click(Sender: TObject);
begin
 IsDouble := False;
 Sleep(100);
 Application.ProcessMessages;
 If Not ISDouble then
 begin
 //single click handling routine here
   showmessage('Single');
 End;
end;

procedure TForm1.Memo1DblClick(Sender: TObject);
begin
  showmessage('Double');
  IsDouble := True;
end;

end.


HTH,
...Shu
0
 
LVL 5

Expert Comment

by:snehanshu
ID: 9829744
Here's code that reads the doubleclick interval from the registry and sleeps for that amount of time. I am not a TRegistry expert, but this does the work for me :)

Cheers!
...Shu

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    procedure Memo1Click(Sender: TObject);
    procedure Memo1DblClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  IsDouble: Boolean;

implementation

{$R *.dfm}

procedure TForm1.Memo1Click(Sender: TObject);
Var
  MyReg: TRegistry;
  MyInterval : Integer;
begin

 try
   begin
     MyReg := TRegistry.Create(KEY_READ);
     MyReg.RootKey := HKEY_CURRENT_USER;
     MyReg.OpenKey('Control Panel\Mouse',False);
     MyInterval := StrToIntDef(MyReg.ReadString('DoubleClickSpeed'), 250);
   end
 except
   begin
     MyInterval := 250;//default mouse dblclick interval
   end
 end;
 if assigned(MyReg) then
   MyReg.Free;

 IsDouble := False;
 Sleep(MyInterval);
 Application.ProcessMessages;
 If Not ISDouble then
 begin
 //single click handling routine here
   showmessage('Single');
 End;
end;

procedure TForm1.Memo1DblClick(Sender: TObject);
begin
  showmessage('Double');
  IsDouble := True;
end;

end.
0
 
LVL 9

Accepted Solution

by:
mocarts earned 300 total points
ID: 9830447
hi, TDK_man
Shu is right about main idea, but there is a way for shorter code (and easier to support):

procedure TForm1.Memo1Click(Sender: TObject);
begin
  Memo1.Lines.Add('Click');
  // call windows api function to retrieve system setting for double click time
  // this setting depends on user preferences - by default there will be very slow response time for Click
  // but you can tune that by subtracting some variable (programm setting) value from function result
  Timer1.Interval := GetDoubleClickTime;
  Timer1.Enabled := True;
end;

procedure TForm1.Memo1DblClick(Sender: TObject);
begin
  Timer1.Enabled := False;
  Memo1.Lines.Add('DblClick');
  // your OnDblClick code here
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Timer1.Enabled := False;
  Memo1.Lines.Add('Click-Timer');
  // your OnClick code here
end;

wbr, mo.
0
 
LVL 7

Expert Comment

by:sftweng
ID: 9832708
Have you tried changing the double-click timing to a faster setting in Windows -> Control Panel -> Mouse?
0
 
LVL 1

Author Comment

by:tdk_man
ID: 9839076
Sorry for the delay in getting back - I had a power cut and my UPS failed. I ended up having to re-install Windows and all my software.

Will check out all the suggestions (thanks for them) this weekend and get back...

TDK_Man
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

688 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