Recent

Author Topic: TUpDown increase button starts decreasing after value reaches 100  (Read 2320 times)

CM630

  • Hero Member
  • *****
  • Posts: 1700
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
I have not seen it myself, but while investigating a bug report there ocurred to be a problem with the TUpDown control in MacOs.
Here is the snippet:

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls, StdCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Label1: TLabel;
  16.     UpDown1: TUpDown;
  17.     procedure FormCreate(Sender: TObject);
  18.     procedure UpDown1Click(Sender: TObject; Button: TUDBtnType);
  19.   private
  20.  
  21.   public
  22.  
  23.   end;
  24.  
  25. var
  26.   Form1: TForm1;
  27.   Indication : integer = 0;
  28.  
  29. implementation
  30.  
  31. {$R *.lfm}
  32.  
  33. { TForm1 }
  34.  
  35. procedure TForm1.UpDown1Click(Sender: TObject; Button: TUDBtnType);
  36. begin
  37.    if (Button = btNext)
  38.     then inc(Indication,1)
  39.     else dec(Indication,1);
  40.   Label1.Caption := IntToStr(Indication);
  41. end;
  42.  
  43. procedure TForm1.FormCreate(Sender: TObject);
  44. begin
  45.     Label1.Caption := IntToStr(Indication);
  46. end;
  47.  
  48. end.
  49.  
When the Up button is held, initially Indication increases. But after it reaches (or exceeds) 100, it starts decreasing.
The issue is not observed on Windows and Linux (Mint Mate).

It was reported on MacOs El Capitan, but AFAIU it was observed also on another MacOS version, I will add this info when available.
The executable was built with Lazarus 4.2.
« Last Edit: August 06, 2025, 11:42:38 am by CM630 »
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

wp

  • Hero Member
  • *****
  • Posts: 13565
Re: TUpDown increase button starts decreasing after value reaches 100
« Reply #1 on: August 06, 2025, 12:05:48 pm »
Yes, I confirm this. It seems as if the upper buttons mysteriously changes to btPrev when the upper limit is reached (this does not happen with the lower button correspondingly, and when the initial Indicator value is > 0 the direction change happens later).

But when I display the value of the UpDown's Position property everything is correct (like in Windows), and when the Wrap property is active and a limit is reached the Position jumps to the other end and continues running, as expected.

CM630

  • Hero Member
  • *****
  • Posts: 1700
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: TUpDown increase button starts decreasing after value reaches 100
« Reply #2 on: August 06, 2025, 12:47:03 pm »
So if I get you right:
1. I shall create bug report for that (I sought the bugtracker and did not find it described).
2. UpDown1.Wrap := True; can be used as a workaround in this case, because the position is not used?

I was thinking about
Code: Pascal  [Select][+][-]
  1. procedure TForm1.UpDown1Click(Sender: TObject; Button: TUDBtnType);
  2. begin
  3.   UpDown1.Position := 0;  
  4. ...
  5. end;
but if wrap = True is fine, then it is fine.

(I do not have a modern Mac, so I cannot try these myself)
« Last Edit: August 06, 2025, 12:48:42 pm by CM630 »
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

wp

  • Hero Member
  • *****
  • Posts: 13565
Re: TUpDown increase button starts decreasing after value reaches 100
« Reply #3 on: August 06, 2025, 01:22:28 pm »
I wonder why you introduce your own counting variable "Indication", rather than using the UpDown.Position which is just there for this exact purpose. And it is working correctly (at least on my VirtualBox on Windows with mac OS X 10.14 VM).

CM630

  • Hero Member
  • *****
  • Posts: 1700
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: TUpDown increase button starts decreasing after value reaches 100
« Reply #4 on: August 06, 2025, 01:32:30 pm »
In this particular case, TUpDown is a part of a custom control, the .Position property is not used.
What is used is Up and Down, received as Button: TUDBtnType in OnUpDown1Click.


Reported as https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/41792
« Last Edit: August 06, 2025, 10:04:45 pm by CM630 »
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

Bart

  • Hero Member
  • *****
  • Posts: 5730
    • Bart en Mariska's Webstek
Re: TUpDown increase button starts decreasing after value reaches 100
« Reply #5 on: August 06, 2025, 10:25:45 pm »
If TSpinEditEx works correct on Mac OS X, then you can take a look at how I implemented it ("communciation" between edit and updown) there?

Bart

CM630

  • Hero Member
  • *****
  • Posts: 1700
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: TUpDown increase button starts decreasing after value reaches 100
« Reply #6 on: August 08, 2025, 08:37:57 am »
If TSpinEditEx works correct on Mac OS X, then you can take a look at how I implemented it ("communciation" between edit and updown) there?

Bart
I am not sure that I understood you, do you mean that I could find a workaround in the code of TSpinEditEx?
I was told that UpDown.Wrap := True worked in our case, but that does not make the bug in TUpDown non-existent.

...And it is working correctly (at least on my VirtualBox on Windows with mac OS X 10.14 VM)...
I was wondering if MacOS is installable on VirtualBox and how legal it is. I should try to install it.
I have a PPC Mac, I doubt that I could test anything on it.
« Last Edit: August 08, 2025, 08:40:56 am by CM630 »
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

Bart

  • Hero Member
  • *****
  • Posts: 5730
    • Bart en Mariska's Webstek
Re: TUpDown increase button starts decreasing after value reaches 100
« Reply #7 on: August 08, 2025, 09:24:14 am »
I am not sure that I understood you, do you mean that I could find a workaround in the code of TSpinEditEx?
I was told that UpDown.Wrap := True worked in our case, but that does not make the bug in TUpDown non-existent.

I was suggesting to look a TSppinEditEx to see wether I implemented it defferently than you did.
If so, and if TSpinEditEx does not have this buggy behaviour, then you could possibly have a workaround.

I did not imply that the bug was not there, just offered a suggestion to get around it.

Bart

CM630

  • Hero Member
  • *****
  • Posts: 1700
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: TUpDown increase button starts decreasing after value reaches 100
« Reply #8 on: August 08, 2025, 10:46:21 am »
There is already a working workaround (I was told), but maybe TSpinEditEx will also misbehave in MacOS.
In spinex.inc there is

Code: Pascal  [Select][+][-]
  1. procedure TSpinEditExBase.UpDownClick(Sender: TObject; {%H-}Button: TUDBtnType);
  2. begin
  3.   BuddyClick;
  4. end;  

{%H-} seems to be sth. for Delphi compatibility, and Button does not seem to be used, so maybe everything will be fine.
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

Bart

  • Hero Member
  • *****
  • Posts: 5730
    • Bart en Mariska's Webstek
Re: TUpDown increase button starts decreasing after value reaches 100
« Reply #9 on: August 08, 2025, 03:40:39 pm »
IIRC this just calls the OnClick handler.
The internal logic (increment/decrement) is somewhere else I think.

But you can just test TSpinEditEx with a Max > 100 and see what happens?
I have no access to a Mac, so I can't.

Bart

 

TinyPortal © 2005-2018