Solved

TUpDown bug

Posted on 2002-07-18
7
1,195 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

690 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