?
Solved

TUpDown bug

Posted on 2002-07-18
7
Medium Priority
?
1,225 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 7

Accepted Solution

by:
Cynna earned 200 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

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!

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month12 days, 9 hours left to enroll

777 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