Solved

TUpDown bug

Posted on 2002-07-18
7
1,188 Views
Last Modified: 2010-05-18
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);
begin
  Edit2.Text :=   IntToStr(ord(Button));
end;

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?
0
Comment
Question by:isstorr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 10

Expert Comment

by:kacor
ID: 7162099
Hi,

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

TCustomUpDown.Wrap

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

property Wrap: Boolean;

Description

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

Janos
0
 
LVL 2

Author Comment

by:isstorr
ID: 7162110
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.
0
 
LVL 14

Expert Comment

by:AvonWyss
ID: 7162203
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).
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Accepted Solution

by:
Cynna earned 50 total points
ID: 7164188
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;
begin
   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;
        end
        else LastPeaked:=FALSE;
   // Up now containes pressed button:
   if Up then Edit2.Text :='Up' else Edit2.Text :='Down'
end;

0
 
LVL 2

Author Comment

by:isstorr
ID: 7164289
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.
0
 
LVL 10

Expert Comment

by:kacor
ID: 7164814
Hi isstorr,

sorry for the misunderstand

wbr

Janos
0
 
LVL 2

Author Comment

by:isstorr
ID: 7165086
np :)
thanks again for your input every1
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question