Solved

Button stay down

Posted on 2001-07-04
5
623 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now