Board index » delphi » Click and Double Click

Click and Double Click

What am I doing wrong?

I start a new application and a form is created. I add two events OnClick
and On DblClick by double clicking the relevant events in the "events" page
of Object Inspector. In the method for each of these events I add the code

begin
    beep;
end;

I create a breakpoint at each of these two "beep" statements.

I now run the program. When I single click in the form, the program stops in
TForm1.FormClick. I now double click in the form. The program stops at the
breakpoint in TForm1.FormClick. I then press F9 to resume execution and the
program stops at the breakpoint in TForm1.FormDblClick.

Is this normal? I would have thought that in the latter case double clicking
the form would have immediately passed control to the event handler for the
Double Click.

 

Re:Click and Double Click


Quote
> Is this normal? I would have thought that in the latter case double
clicking
> the form would have immediately passed control to the event handler for
the
> Double Click.

Nope, because you FIRST single-click (the first time you press the
mousebutton), your computers does NOT know whether you are going to click
again, and if so, it passes control to your DblClick event handler. It is
simply because your computer doesn't know what you're going to do.
--
uws
MAILTO:  ln.bewfmt.eelretslob@spuorgswen  BACKWARDS!
BEWARE: All your NEWS are belong to us!

Re:Click and Double Click


"Mike Price" <mike.pr...@cern.ch> skrev i en meddelelse
news:99dq8g$se8$1@sunnews.cern.ch...

Quote
> What am I doing wrong?

Nothing, just a lack of windows knowledge.

Quote
> I now run the program. When I single click in the form, the program stops
in
> TForm1.FormClick. I now double click in the form. The program stops at the
> breakpoint in TForm1.FormClick. I then press F9 to resume execution and
the
> program stops at the breakpoint in TForm1.FormDblClick.
> Is this normal?

Yes, it's normal.

Quote
> I would have thought that in the latter case double clicking
> the form would have immediately passed control to the event handler for
the
> Double Click.

A double click always results in first a click event and then the double
click event.
This is normal Windows behaviour.

Finn Tolderlund

Re:Click and Double Click


Quote
> Nothing, just a lack of windows knowledge.
> A double click always results in first a click event and then the double
> click event.
> This is normal Windows behaviour.

Yep

Found that out on a few things i tried
with a Click and DblClick event.

Both clicks you perform are in the initial
stage of a single Click, with (I guess) a register
holding the microseconds elapsed and another
register holding the number of times the mouse
was clicked...and yet another register holding
the button clicked(right,left,center).

(maybe 1 register holds these values with the corresponding
bits set...just a guess)

Based on these values, the OS reacts.

Re:Click and Double Click


In article <1Duu6.70$zW6.64533...@news.mobilixnet.dk>, "Finn Tolderlund"

Quote
<XnospamYfinn.tolderlu...@Ymobilixnet.dkXnospamY> wrote:
>"Mike Price" <mike.pr...@cern.ch> skrev i en meddelelse
>news:99dq8g$se8$1@sunnews.cern.ch...
>> What am I doing wrong?

>Nothing, just a lack of windows knowledge.

>> I now run the program. When I single click in the form, the program stops
>in
>> TForm1.FormClick. I now double click in the form. The program stops at the
>> breakpoint in TForm1.FormClick. I then press F9 to resume execution and
>the
>> program stops at the breakpoint in TForm1.FormDblClick.
>> Is this normal?

>Yes, it's normal.

>> I would have thought that in the latter case double clicking
>> the form would have immediately passed control to the event handler for
>the
>> Double Click.

>A double click always results in first a click event and then the double
>click event.
>This is normal Windows behaviour.

Warning: Delphi and Windows newbie speaking...

Excuse me for being appalled at this.  It reminds me of a product I once
worked on.  It had a built-in keyboard whose keys could be pressed singly,
or in combinations of two or three keys at once.  Because the keyboard
manager was written by a moron, whenever you pressed a key combination,
the key event for the first keypress was FIRST put into the queue....
This mattered, since the product did live video editing and the combos
were used to change things like background colour, etc....groan....

A double mouse click is a SEMANTIC EVENT.  It is not a funny sort of
single mouse click.  I am nothing short of appalled that Windows does
things in this way.  There was presumably nothing to prevent them from
storing the first click for a few milliseconds in case a second one came
along quick enough, AND THEN reporting JUST the double-click event.

Rant over.  What are we to do if we want to respond to both types of
events, in different ways?  The usual GUI rules don't get in the way here;
single click is select, double click is "do something", and it's nice to
see the thing being selected first.  But what if there are incompatible
actions required for single and double click?  Has anyone met and solved
this problem?
--
Esther Michaels
Please respond to newsgroup; I don't check my mail account

Re:Click and Double Click


On Mon, 26 Mar 2001 08:32:28 +1200, e_...@my-deja.com (Esther

Quote
Michaels) wrote:

>.  But what if there are incompatible
>actions required for single and double click?  Has anyone met and solved
>this problem?
>--
>Esther Michaels
>Please respond to newsgroup; I don't check my mail account

Yup - just check the Click event - if it is within N milli secs of the
last then it as a double click.

Re:Click and Double Click


Quote
"Esther Michaels" <e_...@my-deja.com> wrote in message news:e_r_m-
> Rant over.  What are we to do if we want to respond to both types of
> events, in different ways?  The usual GUI rules don't get in the way here;
> single click is select, double click is "do something", and it's nice to
> see the thing being selected first.  But what if there are incompatible
> actions required for single and double click?  Has anyone met and solved
> this problem?

I understand and sympathise, its much like I felt when I first encountered
the behavior. However, mull it over. I think eventually you will come to
realize that it is actually a good thing . . . well at least the only
reasonable way to do things, especially given some historical context.

Remember that this behavior would probably have been defined back in the
good (not) old Win 1.0 days. Machines (micros) back then were lucky to run
at more than 16MHz. Pre-emptive multi-tasking didn't exist on micros, etc.
etc. If memory serves, the double click period was also fairly long.

In every case where I have initially wanted to use a click and double click
for incompatible tasks I've come to realize that the design was poor. Having
to re-evaluate/re-design the desired interface has lead to a much better ui.
While I'm not willing to state a general case, I do believe that its
probable good ui design and adherence to Win standards (like them or not) is
incompatible with conflicting semantics between single and double clicks.

Finally, programs would be much more sluggish if they had to wait the full
double-click time before they could react to a click. People notice delays
as low as 200 ms. I believe that most systems have their double click time
set longer.

All that being said. If one has to do it, it can be done. Have the click
event start a timer with an interval a little longer than the double click
time on the system. Disable the timer in the double click event. Put the
click code in the timer's event.

Re:Click and Double Click


In article <YeAv6.13698$TW.55...@tor-nn1.netcom.ca>, "Bruce Roberts"

Quote
<b...@bounceitattcanada.xnet> wrote:
>"Esther Michaels" <e_...@my-deja.com> wrote in message news:e_r_m-

>> Rant over.  What are we to do if we want to respond to both types of
>> events, in different ways?  The usual GUI rules don't get in the way here;
>> single click is select, double click is "do something", and it's nice to
>> see the thing being selected first.  But what if there are incompatible
>> actions required for single and double click?  Has anyone met and solved
>> this problem?

>I understand and sympathise, its much like I felt when I first encountered
>the behavior. However, mull it over. I think eventually you will come to
>realize that it is actually a good thing . . . well at least the only
>reasonable way to do things, especially given some historical context.

>Remember that this behavior would probably have been defined back in the
>good (not) old Win 1.0 days. Machines (micros) back then were lucky to run
>at more than 16MHz. Pre-emptive multi-tasking didn't exist on micros, etc.
>etc. If memory serves, the double click period was also fairly long.

>In every case where I have initially wanted to use a click and double click
>for incompatible tasks I've come to realize that the design was poor. Having
>to re-evaluate/re-design the desired interface has lead to a much better ui.
>While I'm not willing to state a general case, I do believe that its
>probable good ui design and adherence to Win standards (like them or not) is
>incompatible with conflicting semantics between single and double clicks.

>Finally, programs would be much more sluggish if they had to wait the full
>double-click time before they could react to a click. People notice delays
>as low as 200 ms. I believe that most systems have their double click time
>set longer.

>All that being said. If one has to do it, it can be done. Have the click
>event start a timer with an interval a little longer than the double click
>time on the system. Disable the timer in the double click event. Put the
>click code in the timer's event.

Thanks Bruce!  All good points that you raise.  I'm not certain there
would be a case where the semantics of single and double click would
rightly be very different from each other, but the possibility concerned
me.  I'm glad to see that there is a way of handling it.  (Quite obvious,
even to a newbie like me, once I saw it.)  Thanks again
--
Esther Michaels
Please respond to newsgroup; I don't check my mail account

Other Threads