Lazarus

Programming => LCL => Topic started by: Handoko on May 29, 2017, 08:17:43 pm

Title: TForm.OnMouseLeave not working
Post by: Handoko on May 29, 2017, 08:17:43 pm
As the title said, TForm.OnMouseLeave is not working correctly. I'm using Ubuntu Mate 16.10 64-bit Lazarus 1.6.4 FPC 3.0.2 GTK2.

You can try putting this code in OnMouseEnter and OnMouseLeave events:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormMouseEnter(Sender: TObject);
  2. begin
  3.   Caption := 'Mouse Entered';
  4. end;
  5.  
  6. procedure TForm1.FormMouseLeave(Sender: TObject);
  7. begin
  8.   Caption := 'Mouse Left';
  9. end;

Does it work on your test? Let me know, so I will report it to the bug tracker forum.
Title: Re: TForm.OnMouseLeave not working
Post by: GAN on May 29, 2017, 08:38:01 pm
Yes, you're right, when I pass the mouse over a button or a grid of the form, then display "mouse left".

Linux Mint 17.2 64 bit Mate GTK2 - Lazarus 1.6 FPC 3.0.0
Title: Re: TForm.OnMouseLeave not working
Post by: Handoko on May 29, 2017, 08:57:51 pm
Maybe I don't understand how the Mouse Leave works. But I think it has 2 issues:

- If we move the mouse pointer to other controls (for example a button), that is still inside the form the OnMouseLeave will be triggered. I think it is wrong because that control is inside the form. Correct me if I'm wrong.

- If we move the mouse pointer from inside to the outside of the form, the OnMouseLeave will not be triggered. It is definitely wrong. (Actually, it will be triggered but at very low chances, perhaps 1% only)

Any test from others, maybe Windows?
Title: Re: TForm.OnMouseLeave not working
Post by: balazsszekely on May 29, 2017, 10:40:28 pm
Quote
@Handoko
Does it work on your test? Let me know, so I will report it to the bug tracker forum.
It works both under windows and linux, but only if the form is empty. If you place another control, for example a memo with align-->alClient, the events are not triggered and AFAIK this is the intended behavior, because now the OnMouseEnter of the Memo is triggered instead.

As a workaround you can do something like this:
1. Drop a timer to your form, set interval to 50 ms
2. Declare a private variable FMouseOverForm
Code: Pascal  [Select][+][-]
  1. uses LCLIntf;
  2.  
  3. procedure TForm1.tmTimer(Sender: TObject);
  4. var
  5.   P: TPoint;
  6. begin
  7.   GetCursorPos(P);
  8.   P := ScreenToClient(P);
  9.   if (PtInRect(ClientRect, P)) and (not FMouseOverForm) then
  10.   begin
  11.     Caption := 'Mouse enter';
  12.     FMouseOverForm := True;
  13.   end else if (not PtInRect(ClientRect, P)) and (FMouseOverForm) then
  14.   begin
  15.     Caption := 'Mouse leave';
  16.     FMouseOverForm := False;
  17.   end;
  18. end;


PS: Alternatively you can redirect all OnMouseEnter/OnMouseLeave to a single event.
Title: Re: TForm.OnMouseLeave not working
Post by: Handoko on May 30, 2017, 03:57:51 am
You solution using TTimer worked. And I understand your explanation about that intended behavior.

But you should test it yourself. On an empty form and move your the mouse pointer from inside to outside. It really a bug. 99% it won't be triggered, and only in some random chances it will be triggered correctly.

It could be something wrong with my Lazarus installation. But I won't think so because this trivial issue already bugged me from some previous versions.
Title: Re: TForm.OnMouseLeave not working
Post by: sky_khan on May 30, 2017, 05:11:29 am
On windows (this is what i know), your window(form) wont get any messages when mouse not in your form. Only the window under mouse get windows messages. So when mouse leaves your form you're at dark. As far as I remember it is same in Delphi too.
Title: Re: TForm.OnMouseLeave not working
Post by: Handoko on May 30, 2017, 06:03:47 am
Sounds reasonable. Because if the mouse pointer is no longer hovering on the window, it won't be monitored.

But it doesn't explain why on my test it still able to trigger OnMouseLeave event but only at very low rate.

Okay, let me explain what I actually want to do. I want to customize TDrawGrid appearance using OnCellDraw and OnPrepareCanvas. It worked, but I got mouse hovering problem. I want the cells will be automatically highlighted when the mouse hovering on it and the highlight is removed when the mouse pointer if not on the cell.

Below is the code, to make it simple I used TStringGrid and removed all unnecessary things:

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Forms, Graphics, Grids;
  9.  
  10. type
  11.  
  12.   TForm1 = class(TForm)
  13.     StringGrid1: TStringGrid;
  14.     procedure FormCreate(Sender: TObject);
  15.     procedure StringGrid1PrepareCanvas(sender: TObject; aCol, aRow: Integer;
  16.       aState: TGridDrawState);
  17.   end;
  18.  
  19. var
  20.   Form1: TForm1;
  21.  
  22. implementation
  23.  
  24. {$R *.lfm}
  25.  
  26. procedure TForm1.StringGrid1PrepareCanvas(sender: TObject; aCol, aRow: Integer;
  27.   aState: TGridDrawState);
  28. begin
  29.   if gdHot in aState then
  30.     (sender as TStringGrid).Canvas.Brush.Color := clRed;
  31. end;
  32.  
  33. procedure TForm1.FormCreate(Sender: TObject);
  34. begin
  35.   StringGrid1.Options := StringGrid1.Options + [goHeaderHotTracking];
  36. end;
  37.  
  38. end.

Try to move your mouse pointer to highlight the cells and slowly move it outside. It should work correctly, but try it again with moving your mouse very quickly. The highlight won't be removed.

What I thought is perhaps because the mouse pointer movement is too fast, the grid doesn't properly detected the mouse leaving (from grid to the form). So, I think to solve it by adding code on TForm.OnMouseLeave to remove the grid highlight.

I also provided the downloadable code (test.zip) for you to test. Does it happen on Linux GTK2 only or also on other systems?
Title: Re: TForm.OnMouseLeave not working
Post by: balazsszekely on May 30, 2017, 06:18:09 am
@Handoko
I tested your demo application. Under windows the cell highlight is always removed no matter how fast I move my mouse. Under Linux(Gtk2) I was able to reproduce the issue, but even there only 1 times out of 10.
Title: Re: TForm.OnMouseLeave not working
Post by: Handoko on May 30, 2017, 06:27:17 am
Thank you for testing it.

So, so far the conclusion is:
- On Windows, (visual components') mouse leaving is working as intended
- On Linux Gtk2, the mouse leaving is not 100% working

Any volunteer help me testing the code, please?
Title: Re: TForm.OnMouseLeave not working
Post by: sky_khan on May 30, 2017, 06:30:08 am
On Windows 10 I could make it. I tried to move mouse too fast from grid to out of form, one in 8-10 times it stucks. I guess I can find a solution by using winapi but I dont know much about gtk or qt widgetsets.
Title: Re: TForm.OnMouseLeave not working
Post by: Handoko on May 30, 2017, 06:38:15 am
So, the issue is reproducible. On my tests it almost always happens. Maybe because I use Compiz to add effects on my windows manager.

Using winapi to solve the issue on Windows is okay. But we know writing code to cover a bug isn't a best thing to do. The bug is still there.
Title: Re: TForm.OnMouseLeave not working
Post by: sky_khan on May 30, 2017, 07:04:42 am
Yeah, my solution would be a workaround, not a real fix. You may have to resort to use workarounds if you are under a pressure to ship a software product in real world though :)
Title: Re: TForm.OnMouseLeave not working
Post by: Handoko on May 30, 2017, 07:17:43 am
I don't write program for money. I do programming for fun. It is my personal trayicon Memopad. Very useful for programmers, if you ever used SideKick (for DOS) you know what I mean. It's almost finished just some improvements, I will put it on open source after I fix some remaining issues.

If you have time, please write the workaround. I use Linux but I believe someone will find it useful.
Title: Re: TForm.OnMouseLeave not working
Post by: Ondrej Pokorny on May 30, 2017, 07:55:59 am
IIRC, I fixed this in 1.7. Please retest in 1.8 RC1.
Title: Re: TForm.OnMouseLeave not working
Post by: balazsszekely on May 30, 2017, 08:06:46 am
@Ondrej

It's ok in windows with Lazarus trunk. Under linux(Gtk2) the issue is still present. I can reproduce it, if I try hard enough.
Title: Re: TForm.OnMouseLeave not working
Post by: Handoko on May 30, 2017, 09:03:39 am
Just installed Lazarus 1.8.0RC1 2017-05-15 FPC 3.0.3 x86_64-linux-gtk2 and tested the code. The result is same.

If I move fast enough, the issue is always reproducible.
Title: Re: TForm.OnMouseLeave not working
Post by: Handoko on June 03, 2017, 10:00:42 am
I checked the Lazarus Bugtracker and I found this issue may be related with these:

- 0031511: MouseLeave not called ... gtk2, 2017-03-09
https://bugs.freepascal.org/view.php?id=31511

- 0031510: MouseLeave isn't executed ..., 2017-03-08
https://bugs.freepascal.org/view.php?id=31510

- 0022098: MouseLeave not always fired, 2012-05-22
https://bugs.freepascal.org/view.php?id=22098
Title: Re: TForm.OnMouseLeave not working
Post by: Handoko on February 02, 2020, 10:38:54 am
IIRC, I fixed this in 1.7. Please retest in 1.8 RC1.

I retested the issue again today on Lazarus 2.0.6 GTK2 Ubuntu 19.10, it's still not fixed yet.
Title: Re: TForm.OnMouseLeave not working
Post by: jamie on February 05, 2020, 02:19:27 am
Mouse movements of that nature in windows is a low priority..

a message is sent via the OS but it can get delayed and it can also get trashed.

on my system it seems to work ok but on slower systems the mouse may skip outside the form and if the system is busy it won't get sent.

 maybe the onActivate and OnDeActivate form is what you can use
Title: Re: TForm.OnMouseLeave not working
Post by: Handoko on February 05, 2020, 02:47:46 am
Yes, just like you said if I move the move away slowly there will be no problem. Unfortunately users do not always move the mouse slowly.  :D

On activate/deactive may work but not suitable for the case I want to do.
Title: Re: TForm.OnMouseLeave not working
Post by: jamie on February 05, 2020, 10:40:48 pm
I am not exactly sure what it is  you are doing but I can only assume you are jumping between windows and need to know this information ?

 What I do when using mouse as a free hand drawing or dragging tool I always record the last mouse position I processed and there for I use a Lineto call for free hand drawing instead of a point draw.

 This will guarantee that I do not have any broken lines sections ..

 In your case what you should be doing is recording the MouseMove Plots in a global location so that each time a mouse move is received you can first test to see what the last one was. If the last one was in a different form then you can execute the OnMouseEnter yourself in code.

 When doing such a practice you always record the current location for the next time you receive the message and thus can test for this..

 So basically you need to use the Mouse Move event and do your own Enter and Exit where by you can check the last control it was over.
Title: Re: TForm.OnMouseLeave not working
Post by: winni on February 05, 2020, 11:25:29 pm
Maybe I don't understand how the Mouse Leave works. But I think it has 2 issues:

- If we move the mouse pointer to other controls (for example a button), that is still inside the form the OnMouseLeave will be triggered. I think it is wrong because that control is inside the form. Correct me if I'm wrong.

- If we move the mouse pointer from inside to the outside of the form, the OnMouseLeave will not be triggered. It is definitely wrong. (Actually, it will be triggered but at very low chances, perhaps 1% only)

Any test from others, maybe Windows?

Hi!

In your first szenario the behaviour is correct. The enter/leave event depends on the z-axis : The highest component is triggerd and get the focus - if possible.

OneMouseLeave for a form is not usable. You have to check if it is the Form is active or take the screen coordinates via application.OnMouseMove.

If the MouseLeave/MouseEnter inside an app gets lost you can  use the internal logic:

If the MouseMove of a component is triggered there must definitly  an Enter happend.

If  a MouseMove of anonother neighbour or parent component is triggered, then there must be a mouseleave for the first component.

This problem exists since the last millenium.
And I never had those problems with Delphi

Winni
Title: Re: TForm.OnMouseLeave not working
Post by: Handoko on November 09, 2020, 05:19:55 pm
Hello, I'm back again.
Now with more detailed information.

I am not exactly sure what it is  you are doing ...

Look at the picture below.

I'm designing a form that lets users to select an item from a list. On the right bottom corner, there is an image 'F1', which means users can press F1 or click on the image.

To let user know that image is clickable, I want it to change color (or perhaps change the image to 'click me') when the mouse pointer is hovering on it. So I need to use OnMouseEnter and OnMouseLeave. Unfortunately OnMouseLeave is not 100% triggered. I tested on Lazarus 2.0.10 GTK2 Ubuntu Mate 20.04.

You have to check if it is the Form is active or take the screen coordinates via application.OnMouseMove.

I can't find TApplication.OnMouseMove. Where to find it?





Changing image is not simple so I wrote a demo that use a TButton instead.

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, Forms, Controls, Graphics, ExtCtrls, StdCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     Shape1: TShape;
  17.     procedure Button1MouseEnter(Sender: TObject);
  18.     procedure Button1MouseLeave(Sender: TObject);
  19.   end;
  20.  
  21. var
  22.   Form1: TForm1;
  23.  
  24. implementation
  25.  
  26. {$R *.lfm}
  27.  
  28. { TForm1 }
  29.  
  30. procedure TForm1.Button1MouseEnter(Sender: TObject);
  31. begin
  32.   Shape1.Brush.Color := clBlue;
  33. end;
  34.  
  35. procedure TForm1.Button1MouseLeave(Sender: TObject);
  36. begin
  37.   Shape1.Brush.Color := clWhite;
  38. end;
  39.  
  40. end.

Any solution? Workaround? Or maybe suggestion to use other component?
Title: Re: TForm.OnMouseLeave not working
Post by: winni on November 09, 2020, 06:00:21 pm
Hi Handoko!

To call the mouse from the application you have to use the hook called
Application.AddOnUserInputHandler.

Why ever they hide the word "mouse".

A little example is here:

https://forum.lazarus.freepascal.org/index.php/topic,22815.msg135328.html#msg135328

Winni
Title: Re: TForm.OnMouseLeave not working
Post by: Handoko on November 09, 2020, 07:39:50 pm
I tried you suggestion and wrote a demo using it. Unfortunately the result is the same as using OnMouseLeave. I'm not sure on Windows, but on Linux GTK2 if I move the mouse quickly, it cannot 100% detect mouse outside button positions.

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, sysutils, Forms, Controls, Graphics, ExtCtrls, StdCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     RadioGroup1: TRadioGroup;
  17.     Shape1: TShape;
  18.     procedure MouseInput(Sender: TObject; Msg: Cardinal);
  19.     procedure Button1MouseEnter(Sender: TObject);
  20.     procedure Button1MouseLeave(Sender: TObject);
  21.     procedure FormCreate(Sender: TObject);
  22.   end;
  23.  
  24. var
  25.   Form1: TForm1;
  26.  
  27. implementation
  28.  
  29. {$R *.lfm}
  30.  
  31. { TForm1 }
  32.  
  33. procedure TForm1.MouseInput(Sender: TObject; Msg: Cardinal);
  34. var
  35.   LeftTop, RightBottom: TPoint;
  36.   inRange: Boolean;
  37. begin
  38.   if not(RadioGroup1.ItemIndex = 0) then Exit;
  39.  
  40.   // Button Position
  41.   LeftTop     := Point(Button1.Left, Button1.Top);
  42.   RightBottom := Point(Button1.Left+Button1.Width, Button1.Top+Button1.Height);
  43.   // Convert to screen coordinate
  44.   LeftTop     := ClientToScreen(LeftTop);
  45.   RightBottom := ClientToScreen(RightBottom);
  46.   // Is mouse position in the range of button?
  47.   with Mouse.CursorPos do
  48.     inRange := (X > LeftTop.X) and (X < RightBottom.X) and
  49.       (Y > LeftTop.Y) and (Y < RightBottom.Y);
  50.   // Change color
  51.   case inRange of
  52.     True:  Shape1.Brush.Color := clGreen;
  53.     False: Shape1.Brush.Color := clWhite;
  54.   end;
  55. end;
  56.  
  57. procedure TForm1.Button1MouseEnter(Sender: TObject);
  58. begin
  59.   if not(RadioGroup1.ItemIndex = 1) then Exit;
  60.   Shape1.Brush.Color := clBlue;
  61. end;
  62.  
  63. procedure TForm1.Button1MouseLeave(Sender: TObject);
  64. begin
  65.   if not(RadioGroup1.ItemIndex = 1) then Exit;
  66.   Shape1.Brush.Color := clWhite;
  67. end;
  68.  
  69. procedure TForm1.FormCreate(Sender: TObject);
  70. begin
  71.   Application.AddOnUserInputHandler(@MouseInput, True);
  72.   RadioGroup1.ItemIndex := 0;
  73. end;
  74.  
  75. end.
Title: Re: TForm.OnMouseLeave not working
Post by: jamie on November 09, 2020, 11:39:26 pm
use a borderless control and set the cursor shape to a custom shape? at least it will change to a different shape as you pass over it.
Title: Re: TForm.OnMouseLeave not working
Post by: winni on November 10, 2020, 12:44:44 am
Hi Handoko!

I tested your code: Everything works fine. With a quick mouse. With a very slow mouse.
Everything is ok.

Perhaps you moan about the 1 Pixel in X and one Pixel in Y:

Always the same  with the TRect:

TopLeft is INSIDE the button.
BottomRight is OUTSIDE the button.

So your code has to be:

with Mouse.CursorPos do
    inRange := (X >= LeftTop.X) and (X < RightBottom.X) and
      (Y >= LeftTop.Y) and (Y < RightBottom.Y);

Now the last pixels are found:

System: Lin64, fpc 3.04 Lazarus 2.0.10 gtk2

Winni
 
Title: Re: TForm.OnMouseLeave not working
Post by: jamie on November 10, 2020, 01:50:56 am
Reason to use the  PtInRect function  :D
Title: Re: TForm.OnMouseLeave not working
Post by: winni on November 10, 2020, 02:44:43 am
Hi Jamie!

Which PtInRect  do you use?

Windows?  LCLIntf?  jedi?  types?

I swear the are some more.

But a simple const like
Code: Pascal  [Select][+][-]
  1.  
  2. HexChars=['0'..'9','a'..'f','A'..'F'];

is missing.

Winni
Title: Re: TForm.OnMouseLeave not working
Post by: winni on November 10, 2020, 02:52:45 am
 

Another one:

PointInRect 

in leakview

Winni
Title: Re: TForm.OnMouseLeave not working
Post by: jamie on November 10, 2020, 03:00:23 am
I aways use PtInRect because its a API call in windows if you reference it from the Windows unit but, its actually faster to use it locally instead.

if you use the LCLintf unit it cantains it so it will work in all worlds.

PointInRect must be someone's nightmare idea cause its just a repeat unless it uses different sub member types, like floats maybe?

also with a TRect it has helpers..
 
aRect.Contains(ThePoint) etc..

 you could make up your rectangle on the fly I guess.

 Rect(x,y,x2,y2).Contains(thePoint)

and I think there is also an overload to check if another Trect fits in there too.
Title: Re: TForm.OnMouseLeave not working
Post by: Handoko on November 10, 2020, 03:06:04 am
Perhaps you moan about the 1 Pixel in X and one Pixel in Y:

I don't need high accuracy. But if you think that could be the problem, okay I tried it. Modified the code and run it again. That made no difference. Still got many misses.

use a borderless control and set the cursor shape to a custom shape? at least it will change to a different shape as you pass over it.

Which component will you suggest? The code provided is only a demo, actually I will use a TImage.

Reason to use the  PtInRect function  :D

I knew PtInRect. But using PtInRect or not should not cause the issue.

I tested your code: Everything works fine. With a quick mouse.

Could it be a platform specific issue? I use Ubuntu Mate 20.04.
Title: Re: TForm.OnMouseLeave not working
Post by: winni on November 10, 2020, 03:23:32 am
Hi Handoko!

Slow computer? Slow Graphics?

I use a Ryzen 5 with Radeon Vega on the CPU (or whatever they call it now).

But look this forum for OS trouble related to fpc/Laz:

* Unbeaten numer one is the Mac
* But No 2 is Ubuntu with it's problems

To use Debian as base for a desktop PC is a strange decision.
Debian is the worst Linux related to the desktop.
It is designed to be a robust long term server OS.
And that it is.

Take another Linux. I am not the one to convince you to Suse.
There are a lot of other good distros.

Winni
Title: Re: TForm.OnMouseLeave not working
Post by: Handoko on November 10, 2020, 03:43:27 am
The code is simply reading mouse position and do comparison, it should be able to run on very old computers. Yes, I am using Core2Duo with integrated VGA, not a high-end machine. But I still can play many 3D games.

If I just want to do mouse onHover effect, which commonly used on websites. It sounds bad if the program requires high specification machines.

Changing OS may solve the problem. But that does not really fix the issue.

I examine AddOnUserInputHandler you suggested. I found that it won't be fired if the mouse pointer is outside the form.
Title: Re: TForm.OnMouseLeave not working
Post by: winni on November 10, 2020, 02:07:41 pm

Changing OS may solve the problem. But that does not really fix the issue.

I examine AddOnUserInputHandler you suggested. I found that it won't be fired if the mouse pointer is outside the form.

Hi!

Tested your code with Win7 on VirtualBox - works fluently.

The AddOnUserInputHandler  fires only inside your Form(s).
That's why it is named Application.AddOnUserInputHandler .

My workaround for your problem is this:

* Put a timer on your form
* Set the tick intervall to 100 ms

Add the TimerEvent:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Timer1Timer(Sender: TObject);
  2. begin
  3.   Caption:= IntToStr(Mouse.CursorPos.x)+' / '+IntToStr(Mouse.CursorPos.y);
  4. end;
  5.  

Now move your mouse outside the Form.
And inside.
You see: the InputHandler of the App is not touched and works still.

Perhaps there is a more intelligent way to do this.
But I have not found.

Winni
Title: Re: TForm.OnMouseLeave not working
Post by: Handoko on November 10, 2020, 02:59:09 pm
Thank you for the suggestion. I already used a TTimer yesterday, before you mentioned it. Yes it works. Not a good solution but indeed is a workaround.

I performed some tests first using a TToolbar, it had OnMouseLeave issue too. So I tested the toolbars of my Pale Moon and Firefox browsers, I was unable to reproduce the issue. Then I tested the toolbar of my Lazarus' compoment tab, the issue was reproducible. So now I believe it is not a problem of my OS.

I am going to dig deeper. It should be a fix or better solution. I don't think Pale Moon and Firefox use a TTimer to make their toolbars to work correctly.  :D


Update:

From the web, I found a Terminal command:
xinput test-xi2 --root

It is for showing the mouse activity. If you run the command without --root, it shows the mouse position only if the pointer is inside the form.

Can anyone find the API? If Lazarus can use the system-wide hook I believe the bug can be fixed.
 
Title: Re: TForm.OnMouseLeave not working
Post by: Handoko on December 23, 2020, 02:11:12 pm
I found the workaround for this issue. Using LM_MOUSELEAVE on the mainform the mouse leave event will be triggered 100%.

Here is the summary:

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, Forms, Controls, Graphics, ExtCtrls, StdCtrls, Messages, LMessages;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     CheckBox1: TCheckBox;
  16.     Shape1: TShape;
  17.     procedure FormCreate(Sender: TObject);
  18.     procedure Shape1MouseEnter(Sender: TObject);
  19.     procedure Shape1MouseLeave(Sender: TObject);
  20.   private
  21.     procedure SysMessage(var Msg: TMessage); message LM_MOUSELEAVE;
  22.   end;
  23.  
  24. var
  25.   Form1: TForm1;
  26.  
  27. implementation
  28.  
  29. {$R *.lfm}
  30.  
  31. { TForm1 }
  32.  
  33. procedure TForm1.FormCreate(Sender: TObject);
  34. begin
  35.   Constraints.MinHeight := 240;
  36.   Constraints.MinWidth  := 320;
  37.   Shape1.Height         := Height - 72;
  38.   Shape1.Width          := Width  - 48;
  39.   Shape1.Anchors        := [akTop, akBottom, akLeft, akRight];
  40. end;
  41.  
  42. procedure TForm1.Shape1MouseEnter(Sender: TObject);
  43. begin
  44.   Caption := 'OnMouseEnter triggered';
  45.   Shape1.Brush.Color := clRed;
  46. end;
  47.  
  48. procedure TForm1.Shape1MouseLeave(Sender: TObject);
  49. begin
  50.   Caption := 'OnMouseLeave triggered';
  51.   Shape1.Brush.Color := clWhite;
  52. end;
  53.  
  54. procedure TForm1.SysMessage(var Msg: TMessage);
  55. begin
  56.   if CheckBox1.Checked then
  57.     Shape1MouseLeave(Self);
  58. end;
  59.  
  60. end.

This is only a workaround, not really a fix for the problem. Maybe can be useful for someone that has same problem in the future.
TinyPortal © 2005-2018