There was an interesting post made on one of the Borland Delphi
newsgroups that I thought everyone should at least be aware of, if they were
not already, and as I don't know how many of you frequent those groups I
thought it might also be a good idea to quote it here.  I was aware of the
left-click situation, but not how to cure it.  I wouldn't consider handling
this carte blanc but I will remember it for times when being able to
over-ride the intentions of a modal form might cause other
problems...especially security problems!

///////////// Start //////////////

"I'm sure that this is probably well-known but it just happened to bite us
in 
the rear just now so I am posting in case others might benefit.

Our app contains a modal form that has a TTimer component that counts down 
and automatically closes the form via setting the modal result and continues

on with processing in the parent form. One of our customers discovered the 
following "features":
1) If you Left-Click the modal form caption and keep the button pressed the 
timer will count down and the modal result will be set but the form will not

close and let processing continue until the button is released.
2) If you Right-Click the modal form caption and keep the button pressed all

processing for that form stops. No events, no messages, no nothing.

Well, because of these "features" certain clever users have learned how to 
abuse the system. Following are the solutions we have come up with which 
seem to do the trick in our case (Make sure the Messages unit is used in 
your interface section):

1) For left click feature - Add the following code right after setting your 
modal result:

    PostMessage(Handle, WM_LBUTTONUP, 0, 0);

    This in effect completes the WM_LBUTTONDOWN message and allows the form 
to close when you want it to.

2) For the right click feature - Since this completely stopped all messages 
from reaching the form our only recourse was to handle the message. Note 
that this will probably disable any system menu access from the caption so 
if you need that this will probably not work - have not tested though. 
Following is the code:

    a) Add to your form descendant the following:

        procedure WMNCRButtonDown(var Message: TWMNCRButtonDown); message 
WM_NCRBUTTONDOWN;

    b) Implement the message handler like so:

        procedure TMyForm.WMNCRButtonDown(var Message: TWMNCRButtonDown);
        begin
          Message.Result := 0; // This handles the message and as a side 
affect prevents the message from ever coming to the form again.
        end;

Anyway, that is our solution for now. If anyone has anything better feel 
free to add. I just thought it was crazy that the right-click feature 
effectively disables the system."

from Robert Meek dba Tangentals Design  CCopyright 2006
Proud to be a moderator of "The Delphi Lists" at elists.org

"When I examine myself and my methods of thought, I come to the conclusion
that the gift of Fantasy has meant more to me then my talent for absorbing
positive knowledge!"
                                                    Albert Einstein



_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

Reply via email to