Solved

TUpDown bug

Posted on 2002-07-18
7
1,151 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
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video discusses moving either the default database or any database to a new volume.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now