Recent

Author Topic: [solved] bug? with (panel)mouseup  (Read 3630 times)

speter

  • Sr. Member
  • ****
  • Posts: 419
[solved] bug? with (panel)mouseup
« on: August 22, 2025, 08:34:34 am »
I've noticed a minor issue with the mouseup event, in panels and maybe other components.

I've attached a project which has 2 panels; both with onmouseup event methods. Each calls a procedure which lists the x,y coord in a memo. The only difference is that I have commented out some of the parameters - to remove the "Parameter "Button" not used" Hint.

When the user clicks in the first panel the displayed coord is 0,0.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.showxy(sender:TObject; x,y : integer);
  2. var
  3.   panel : TPanel;
  4. begin
  5.   panel := TPanel(sender);
  6.   memo1.append(format('%s %d,%d',[panel.name,x,y]));
  7. end;
  8.  
  9. procedure TForm1.Panel_leftMouseUp(Sender: TObject; {Button: TMouseButton;
  10.   Shift: TShiftState;} X, Y: Integer);
  11. begin
  12.   showxy(sender,x,y);
  13. end;
  14.  
  15. procedure TForm1.Panel_rightMouseUp(Sender: TObject; Button: TMouseButton;
  16.   Shift: TShiftState; X, Y: Integer);
  17. begin
  18.   showxy(sender,x,y);
  19. end;

This behaviour is with Lazarus v4.0 / Windows 11.

cheers
S.



« Last Edit: August 23, 2025, 01:36:08 am by speter »
I climbed mighty mountains, and saw that they were actually tiny foothills. :)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11802
  • Debugger - SynEdit - and more
    • wiki
Re: bug? with (panel)mouseup
« Reply #1 on: August 22, 2025, 03:48:40 pm »
You can't modify the procedure declaration.

The caller will always sent all parameters.

If you remove some, then the parameters are still in the memory (or CPU registers). So if you remove "Button", then the value that is sent for "Button" ends up in "X, y". And that obviously wont be the expected value.


Procedure/Functions used in events (set by the form designer / object inspector) are not checked for having the correct param list. They are created once for you. If you change them, then things fail. (and may even crash).

Bart

  • Hero Member
  • *****
  • Posts: 5614
    • Bart en Mariska's Webstek
Re: bug? with (panel)mouseup
« Reply #2 on: August 22, 2025, 11:19:14 pm »
The IDE should safeguard users from doing that.
IIRC then Delphi does so.

Bart

speter

  • Sr. Member
  • ****
  • Posts: 419
Re: bug? with (panel)mouseup
« Reply #3 on: August 23, 2025, 01:35:40 am »
You can't modify the procedure declaration.

The caller will always sent all parameters.
Thanks. I thought that since it compiled, it was allowed for.

The IDE should safeguard users from doing that.
IIRC then Delphi does so.
Agree, but I guess that is a feature request. ;)

cheers
S.

I climbed mighty mountains, and saw that they were actually tiny foothills. :)

Bart

  • Hero Member
  • *****
  • Posts: 5614
    • Bart en Mariska's Webstek
Re: bug? with (panel)mouseup
« Reply #4 on: August 23, 2025, 10:53:06 pm »
Agree, but I guess that is a feature request. ;)

There's a bugreport about it already.

Bart

lazer

  • Sr. Member
  • ****
  • Posts: 269
Re: bug? with (panel)mouseup
« Reply #5 on: September 09, 2025, 04:51:42 am »
You can't modify the procedure declaration.

The caller will always sent all parameters.

If you remove some, then the parameters are still in the memory (or CPU registers). So if you remove "Button", then the value that is sent for "Button" ends up in "X, y". And that obviously wont be the expected value.


Procedure/Functions used in events (set by the form designer / object inspector) are not checked for having the correct param list. They are created once for you. If you change them, then things fail. (and may even crash).

That is insanely silly in what is supposed to be a strictly typed language.  Though I suppose the strings fiasco broke that principal long ago.  :(

However, this topic has explained to me how you can get away with supplying two arguments to a method defined with three. That always looked like C style functions which is not possible in Pascal.
« Last Edit: September 09, 2025, 04:55:26 am by lazer »

Thaddy

  • Hero Member
  • *****
  • Posts: 18324
  • Here stood a man who saw the Elbe and jumped it.
Re: [solved] bug? with (panel)mouseup
« Reply #6 on: September 09, 2025, 06:22:20 am »
Turn the hint simply off:project options|compiler|messages
Or in code:
Code: [Select]
{$warn 5024 off}or on the commandline
Code: Bash  [Select][+][-]
  1. fpc -vm5024 yourprogram.pas
« Last Edit: September 09, 2025, 06:27:13 am by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

lazer

  • Sr. Member
  • ****
  • Posts: 269
Re: [solved] bug? with (panel)mouseup
« Reply #7 on: September 17, 2025, 03:30:01 pm »
Quote
Turn the hint simply off:project options|compiler|messages

I know a guy who had a problem with the oil pressure warning light flickering on and off all the time.
He concluded it was a wiring fault and removed the bulb.

Can you guess what happened next?

jamie

  • Hero Member
  • *****
  • Posts: 7307
Re: [solved] bug? with (panel)mouseup
« Reply #8 on: September 17, 2025, 11:12:58 pm »
Quote
Turn the hint simply off:project options|compiler|messages

I know a guy who had a problem with the oil pressure warning light flickering on and off all the time.
He concluded it was a wiring fault and removed the bulb.

Can you guess what happened next?

If it was a Ford, there is no guessing required.! :o
The only true wisdom is knowing you know nothing

lazer

  • Sr. Member
  • ****
  • Posts: 269
Re: [solved] bug? with (panel)mouseup
« Reply #9 on: September 17, 2025, 11:37:45 pm »
No. Folksvagen, try again.  :D

Nice air cooled engine. Heading north from Alice Springs in November.

jamie

  • Hero Member
  • *****
  • Posts: 7307
Re: [solved] bug? with (panel)mouseup
« Reply #10 on: September 17, 2025, 11:44:18 pm »
Oh, aren't those the ones you need a pull cord on to start them?

Jamie :o
The only true wisdom is knowing you know nothing

speter

  • Sr. Member
  • ****
  • Posts: 419
Re: [solved] bug? with (panel)mouseup
« Reply #11 on: September 18, 2025, 01:00:51 am »
No. Folksvagen, try again.  :D

Nice air cooled engine. Heading north from Alice Springs in November.
Wow, that's a lovely drive, so long as you do it during the middle of the night - spend the days at 3-ways and Katherine; avoiding dawn / dusk at all costs (roo's made a real mess of anything without serious bull-bars). :)
I climbed mighty mountains, and saw that they were actually tiny foothills. :)

 

TinyPortal © 2005-2018