Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1298
  • Last Modified:

TUpDown bug

I've just discovered a strange bug in TUpDown (D5 Enterprise) -

Place a TUpDown and a two TEdits onto a form, set the TUpDown's Wrap property to true, and Associate it with Edit1. Add an OnClick event to show which button was clicked (up or down) -

procedure TForm1.UpDown1Click(Sender: TObject; Button: TUDBtnType);
  Edit2.Text :=   IntToStr(ord(Button));

At the wrap point (by default Min & Max should be 0 & 100 respectively) the Button value is reversed! When the value is 100, clicking the Prev button returns btNext, when the value is 0, clicking the Next button returns btPrev...

Anyone know of a fix?
1 Solution

this is the normal behavior of the control. You see in the Help the followings:


Specifies how the up-down control handles attempts to exceed the value of Max or Min.

property Wrap: Boolean;


Use Wrap to specify whether the up-down control treats the range determined by the Max and Min properties as a continuous loop. If Wrap is True, the value of Position becomes the value of the Min property when the user increments Position beyond the value of Max, and becomes the value of Max when the user decrements Position beyond the value of Min.

with best regards

isstorrAuthor Commented:
Sounds like a bug to me... surely clicking the Prev button should always yield btPrev? The value wraps around correctly, it is just the reported button clicked which is wrong.
No, it's correct behaviour. This makes sure that you can expect the value top have increased when you get a btNext event, or to have decreased when you get a btPrev even (even in the case of a wrap).
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

The "fix" for this would be adding some code:

var LastPeaked: Boolean=TRUE; // Global var

//......your code

procedure TForm1.UpDown1Click(Sender: TObject; Button: TUDBtnType);
var Up: Boolean;
   if ord(Button)=0 then Up:=TRUE else Up:=FALSE;
   with UpDown1 do
        if (Position=Max) or (Position=Min) then begin
           if LastPeaked then Up:=not Up
                         else LastPeaked:=TRUE;
        else LastPeaked:=FALSE;
   // Up now containes pressed button:
   if Up then Edit2.Text :='Up' else Edit2.Text :='Down'

isstorrAuthor Commented:
Thanks Cynna that works great :)

You have a point AvonWyss, its a sort of chicken & egg situation I guess. My argument was that clicking the up button should always yield an 'up button clicked' result, regardless of what happens to the actual value.
Hi isstorr,

sorry for the misunderstand


isstorrAuthor Commented:
np :)
thanks again for your input every1
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now