tdk_man
asked on
Double-Click Without Single
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
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
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.ReadStri ng('Double ClickSpeed '), 250);
end
except
begin
MyInterval := 250;//default mouse dblclick interval
end
end;
if assigned(MyReg) then
MyReg.Free;
IsDouble := False;
Sleep(MyInterval);
Application.ProcessMessage s;
If Not ISDouble then
begin
//single click handling routine here
showmessage('Single');
End;
end;
procedure TForm1.Memo1DblClick(Sende r: TObject);
begin
showmessage('Double');
IsDouble := True;
end;
end.
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.ReadStri
end
except
begin
MyInterval := 250;//default mouse dblclick interval
end
end;
if assigned(MyReg) then
MyReg.Free;
IsDouble := False;
Sleep(MyInterval);
Application.ProcessMessage
If Not ISDouble then
begin
//single click handling routine here
showmessage('Single');
End;
end;
procedure TForm1.Memo1DblClick(Sende
begin
showmessage('Double');
IsDouble := True;
end;
end.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Have you tried changing the double-click timing to a faster setting in Windows -> Control Panel -> Mouse?
ASKER
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
Will check out all the suggestions (thanks for them) this weekend and get back...
TDK_Man
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.ProcessMessage
If Not ISDouble then
begin
//single click handling routine here
showmessage('Single');
End;
end;
procedure TForm1.Memo1DblClick(Sende
begin
showmessage('Double');
IsDouble := True;
end;
end.
HTH,
...Shu