Solved

Button stay down

Posted on 2001-07-04
5
627 Views
Last Modified: 2008-02-01
Hi experts. I have a speedbutton on a form and when I click it I want as popupmenu to appear. Ive got that worked out but the button stays down even though I specifically sets its down property to be false. I've tried stepping through the code with a wtach on and according to that it never gets set to down. The button is not part of a group (groupindex is 0) and the allowallup property is set to true. The code Im using is this

procedure TForm1.btnCalcStatsMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  popctatscalc.popup(mouse.cursorpos.x-x,
                     mouse.cursorpos.y-y+ btncalcctats.height);
end;

Hopefully someone will be able to solve this as its been driving me mad for days

Del
0
Comment
Question by:SkyHook
  • 2
  • 2
5 Comments
 
LVL 5

Accepted Solution

by:
TheNeil earned 200 total points
ID: 6253038
This is more of a nuance than a bug but I've come across it in the past (and it sent me half mad too before I solved it). The problem isn't the code that you're calling but the point that you're calling it from. When you call it on the MouseDown then I'm thinking that creating the popup menu somehow gets Windows confused and it fails to send a mouseup message to the button. As the button never gets the 'mouseup' message it stays down BUT (and this is the killer) it's Down property remains FALSE as it's only down due to the mouse click. Well that's how I see it anyway.

The solution (at last) is simply to move the code into the MouseUp event (simple ehh?)

The Neil =:)
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6253047
I have an ideas, but it's not too nice:

Add a message handler to your form like this:

type
  TYourForm = class...
    ...
  private
    procedure DoPopup(var Message: TMessage); message WM_USER + 777;
  end;

procedure TYourForm.DoPopup(var Message: TMessage);
begin
  popctatscalc.popup(mouse.cursorpos.x-Message.wParam,
                     mouse.cursorpos.y-Message.lParam+btnclcctats.height);
end;

Then in your MouseDown method do this:

procedure TForm1.btnCalcStatsMouseDown(Sender: TObject;
 Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  PostMessage(handle, WM_USER + 777, x, y);
end;

Hopefully this will fix the problem. It's not nice, but I think it should work.

Regards, Madshi.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6253051
Ha, The Neil was faster than me...   (-:
0
 

Author Comment

by:SkyHook
ID: 6253053
TheNeil,

Well I dont know why but that seems to work. Thank you

Del
0
 
LVL 5

Expert Comment

by:TheNeil
ID: 6253070
Thanks Del - Glad to be of help.

Sorry Madshi (he he he) but this is one of those annoying little bug-ettes that Windows throws up every now and then (I was guessing on the missing message but it seems to answer the problem)

The Neil =:)
0

Featured Post

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

810 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