8

I'm porting a Delphi 5 app to D2010, and I've got a bit of a problem. On one form is a TImage component with an OnMouseMove event that's supposed to update a label whenever the mouse is moved over the image. This worked just fine in the original app, but now the OnMouseMove event fires constantly whenever the mouse is over the image, whether it's moving or not, which causes the label to flicker horribly.

Does anyone know what's causing this and how to fix it?

8
  • 4
    This might be related to blogs.msdn.com/oldnewthing/archive/2003/10/01/55108.aspx and blogs.msdn.com/oldnewthing/archive/2009/06/17/9763416.aspx Commented Dec 31, 2009 at 19:56
  • Interesting stuff, but I don't have any "mouse enhancement" programs running. Commented Dec 31, 2009 at 20:31
  • Well, apparently some mouse drivers may cause this too. But it was just a guess what may apply. I have no clue as for the real reason, though. Commented Dec 31, 2009 at 20:45
  • @Mason, I've performed similar to Ken's test on my Vista machine with Delphi 2010 (no updates) and it works as expected. In other words - I couldn't recreate behaviour which you described. Commented Dec 31, 2009 at 20:45
  • If you're getting OnMouseMove events, then it's because the OS is sending wm_MouseMove messages. It's nothing to do with your program. Johannes's second link includes more information in the comments about culprits people have found. Keep digging, and good luck. Commented Dec 31, 2009 at 20:49

3 Answers 3

6

My psychic debugging sense tells me that you are on Windows, the label is a tooltip window and you are updating on every mousemove.

In all seriousness, I've seen this exact thing with tooltip window when we switched to Vista. It seems that more recent versions of the Windows tooltip window somehow generate WM_MOUSEMOVE messages when you update them. The only fix I could find was to only update the label when the text actually changes.

So, If you aren't on windows, Ignore me. But if you are on Windows, try updating the label text only when it actually changes.

Sign up to request clarification or add additional context in comments.

5 Comments

Very lame psychic debugging, as Delphi 2010 is Win32-only. :-)
Should have included: and TLabel is a standard Windows label control and not a tooltip window. <g>
Ah, that sort of kills it then. must be something else. Should I delete this comment?
Nah, don't delete it. It might be useful to someone else who runs across it. Just couldn't pass up the chance. :-) You'll notice I made sure to include the grin and smile, though.
@John : Thanks for not deleting it. I googled "Windows 7 mouse move repeatedly" and this was the first result. I'm programming in .net and I recently had this very problem under Windows 7 and it was solved by not refreshing the tooltip if the text had not changed.
5

Since I couldn't add a comment I'm using the answer section to confirm this behavior change. I have a project that was developed in Delphi 2007 where the OnMouseMove event is only called when the mouse position changes. I found that with XE OnMouseMove is constantly being called for the same code. I don't know why since they're both triggered by WM_MOUSEMOVE.

What I am doing till I get to the bottom of this is to compare the previous XY coordinates and exit if no change:

if ( x = ZoomRect.Right ) and ( y = ZoomRect.Bottom ) then exit ; 

1 Comment

The difference is that in XE the VCL creates a number of classes such as TScrollbarStyleHook with WMMouseMove methods that I assume are there to support Touch and Gestures which were added in 2010(?). I'm not sure what can be done about it.
1

Mason, I can't reproduce this is a new D2010 (Update 4 & 5) VCL Forms application on Windows XP SP2. Here's what I did:

  • File|New|VCL Forms Application
  • Dropped a TImage and TLabel on the form
  • Picked a random image out of the default images folder (GreenBar.bmp) for the TImage.Picture
  • Double-clicked the TImage.OnMouseMove event in the Object Inspector, and added the following code:
 procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); begin Label1.Caption := Format('X: %d Y: %d', [X, Y]); end; 
  • Ran the application (F9).

The label showed "Label1" (the default caption, of course) until I first moved the mouse over the image. It then updated correctly to show the X and Y coordinates. As soon as I moved the mouse pointer out of the image, the label stopped updating.

It appears to be something in your specific code, or something specific to the version of Windows you're using, and not Delphi 2010 itself.

7 Comments

This is in Vista, in case it helps.
@Ken I think that in Mason's example mouse position is updated even when he is not moving it. Therefore, you should test it also by for example incrementing some variable each time the event is fired up cause on a fast graphic card flickerking might be not visible for the same caption values.
@Wodzu: That was the purpose of using the mouse position (X and Y, passed as parameters to the event handler) and Format(). It takes time to call the function and update the label, and it's done rapidly as the mouse moves quickly across the image. Moving off the image quickly as well, the label stops updating.
@Mason: I don't have a Vista machine here, and don't have D2010 installed on one any longer (upgraded to Win7 on that machine).
@Ken yes, but what if the mouse is NOT moving and still the event is beeing fired? On a quick machine you may not notice the refresh of the label and the caption will stay the same.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.