TGet Spinner Bug?

Post Reply
User avatar
Ugo
Posts: 283
Joined: Sat Oct 15, 2005 6:40 am
Location: Turin, Italy

TGet Spinner Bug?

Post by Ugo »

Hi fw's
I found a bug in spinner clause of Tget class

in first time work correctly but if you test up, after down to -1 and up the up see only 0, 1, 0, 1 ...

Test this code:

Code: Select all

#include "FiveWin.ch"
//----------------------------------------------------------------------------//
function Main()
   LOCAL oDlg, oGet, nVal := 0
   DEFINE DIALOG oDlg
   @ 2,1 GET oGet VAR nVal OF oDlg SIZE 50, 12 SPINNER
   ACTIVATE DIALOG oDlg
   RETURN Nil
//------------------------------------------------------------------------------
Ciao, best regards,
Ugo
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: TGet Spinner Bug?

Post by Enrico Maria Giordano »

I don't know why but the following fix seems to work:

Code: Select all

METHOD ScrollNumber( nDirection ) CLASS TGet

   LOCAL nValue, nDec, nPos

   #ifndef __XPP__
      nValue := ::Value
   #else
      nValue := ::VarGet()
   #endif

   nPos := ::nPos

   if !Empty( ::oGet:DecPos ) .and. nPos >= ::oGet:DecPos
      nDec   := Max( 1, nPos - ::oGet:DecPos - 1 )
      If nDirection > 0
         nValue += 1 / ( 10 ^ nDec )
      else
         nValue -= 1 / ( 10 ^ nDec )
      Endif
   else
      nValue += nDirection
   endif

   if nDirection > 0
      if ::bMax != NIL .and. nValue > Eval( ::bMax )
         MessageBeep()
      else
         ::cText( nValue )
      endif
   else
      if ::bMin != NIL .and. nValue < Eval( ::bMin )
         MessageBeep()
      else
         ::cText( nValue )
      endif
   endif

   ::oGet:KillFocus()
   ::oGet:SetFocus()
   ::SetPos( nPos )

RETURN nil
EMG
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: TGet Spinner Bug?

Post by Enrico Maria Giordano »

EnricoMaria wrote:I don't know why but the following fix seems to work:

Code: Select all

METHOD ScrollNumber( nDirection ) CLASS TGet

   LOCAL nValue, nDec, nPos

   #ifndef __XPP__
      nValue := ::Value
   #else
      nValue := ::VarGet()
   #endif

   nPos := ::nPos

   if !Empty( ::oGet:DecPos ) .and. nPos >= ::oGet:DecPos
      nDec   := Max( 1, nPos - ::oGet:DecPos - 1 )
      If nDirection > 0
         nValue += 1 / ( 10 ^ nDec )
      else
         nValue -= 1 / ( 10 ^ nDec )
      Endif
   else
      nValue += nDirection
   endif

   if nDirection > 0
      if ::bMax != NIL .and. nValue > Eval( ::bMax )
         MessageBeep()
      else
         ::cText( nValue )
      endif
   else
      if ::bMin != NIL .and. nValue < Eval( ::bMin )
         MessageBeep()
      else
         ::cText( nValue )
      endif
   endif

   ::oGet:KillFocus() //EMG
   ::oGet:SetFocus() //EMG
   ::SetPos( nPos )

RETURN nil
EMG
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: TGet Spinner Bug?

Post by Enrico Maria Giordano »

I don't know why but the following fix seems to work:

Code: Select all

METHOD ScrollNumber( nDirection ) CLASS TGet

   LOCAL nValue, nDec, nPos

   #ifndef __XPP__
      nValue := ::Value
   #else
      nValue := ::VarGet()
   #endif

   nPos := ::nPos

   if !Empty( ::oGet:DecPos ) .and. nPos >= ::oGet:DecPos
      nDec   := Max( 1, nPos - ::oGet:DecPos - 1 )
      If nDirection > 0
         nValue += 1 / ( 10 ^ nDec )
      else
         nValue -= 1 / ( 10 ^ nDec )
      Endif
   else
      nValue += nDirection
   endif

   if nDirection > 0
      if ::bMax != NIL .and. nValue > Eval( ::bMax )
         MessageBeep()
      else
         ::cText( nValue )
      endif
   else
      if ::bMin != NIL .and. nValue < Eval( ::bMin )
         MessageBeep()
      else
         ::cText( nValue )
      endif
   endif

   ::oGet:KillFocus()
   ::oGet:SetFocus()
   ::SetPos( nPos )

RETURN nil
EMG
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: TGet Spinner Bug?

Post by Enrico Maria Giordano »

I don't know why but the following fix seems to work:

Code: Select all

METHOD ScrollNumber( nDirection ) CLASS TGet

   LOCAL nValue, nDec, nPos

   #ifndef __XPP__
      nValue := ::Value
   #else
      nValue := ::VarGet()
   #endif

   nPos := ::nPos

   if !Empty( ::oGet:DecPos ) .and. nPos >= ::oGet:DecPos
      nDec   := Max( 1, nPos - ::oGet:DecPos - 1 )
      If nDirection > 0
         nValue += 1 / ( 10 ^ nDec )
      else
         nValue -= 1 / ( 10 ^ nDec )
      Endif
   else
      nValue += nDirection
   endif

   if nDirection > 0
      if ::bMax != NIL .and. nValue > Eval( ::bMax )
         MessageBeep()
      else
         ::cText( nValue )
      endif
   else
      if ::bMin != NIL .and. nValue < Eval( ::bMin )
         MessageBeep()
      else
         ::cText( nValue )
      endif
   endif

   ::oGet:KillFocus() //EMG
   ::oGet:SetFocus() //EMG
   ::SetPos( nPos )

RETURN nil
EMG
User avatar
Ugo
Posts: 283
Joined: Sat Oct 15, 2005 6:40 am
Location: Turin, Italy

Re: TGet Spinner Bug?

Post by Ugo »

EnricoMaria wrote:I don't know why but the following fix seems to work:

Code: Select all

METHOD ScrollNumber( nDirection ) CLASS TGet

   LOCAL nValue, nDec, nPos
   ...
   ::oGet:KillFocus()
   ::oGet:SetFocus()
   ::SetPos( nPos )

RETURN nil
EMG
Enrico,
thank you, work perfectly!
Ciao, best regards,
Ugo
User avatar
Ugo
Posts: 283
Joined: Sat Oct 15, 2005 6:40 am
Location: Turin, Italy

Re: TGet Spinner Bug?

Post by Ugo »

EnricoMaria wrote:Sorry... :-(

EMG
Why? :D
Ciao, best regards,
Ugo
User avatar
Ugo
Posts: 283
Joined: Sat Oct 15, 2005 6:40 am
Location: Turin, Italy

Re: TGet Spinner Bug?

Post by Ugo »

EnricoMaria wrote:Sorry for the repeated post.

EMG
Nothing for me!!!
:D
Ciao, best regards,
Ugo
Post Reply