次の方法で共有


Bug: a readonly left-aligned textbox has a floating point number whose value changes

Here’s an interesting bug report. The code below shows two readonly textboxes on a form, both containing floating point values. The first is left-aligned.

When you hit tab from the first textbox, the value changes from 4.011 to 4.000

If you change the Alignment to Right (1) then it works as expected.

Possible alignment property values:

0 = Left

1 = Right

2 = Center

3 = Automatic (Default)

When you tab off the textbox, VFP is trying to match “4.011 ” (trailing spaces) with the default input mask “#######.###” which was set when the value was set.

Since the second character is the decimal place, which does not match the second “#”, the matching stops.

When the value is right aligned, then the textbox has “ 4.011“ (leading spaces) which VFP tries to match with “#######.###” which does not stop prematurely.

When it’s not readonly, then the value is “ 4.011 “ (leading and trailing spaces), which matches the mask.

=== STEPS TO REPRO ===

1. Run code below.

2. Press TAB to move focus from 1st TextBox while watching it's value

OBSERVED: Value in TEXT1 goes from 4.011 to 4.000

EXPECTED: Value in TEXT1 to not change.

COMMENTS: Setting the ALIGNMENT of TEXT1 = 1 or 3, *OR* setting it's READONLY = .F. causes EXPECTED results.

#DEFINE TXT_ALIGN 0

PUBLIC oform1

oform1=NEWOBJECT("form1")

oform1.SHOW

RETURN

DEFINE CLASS form1 AS FORM

      NAME = "Form1"

      ADD OBJECT text1 AS TEXTBOX WITH ;

            ALIGNMENT = TXT_ALIGN, ;

            HEIGHT = 23, LEFT = 108, ;

            READONLY = .T., TOP = 60, ;

            WIDTH = 100, NAME = "Text1"

      ADD OBJECT text2 AS TEXTBOX WITH ;

            ALIGNMENT = 3, HEIGHT = 23, ;

            LEFT = 108, READONLY = .T., ;

            TOP = 96, WIDTH = 100, ;

            NAME = "Text2"

      PROCEDURE INIT

            THIS.text1.VALUE = 4.011

            THIS.text2.VALUE = 4.01001

      ENDPROC

ENDDEFINE

Comments

  • Anonymous
    August 14, 2006
    Changing the initial value to a string also yields the EXPECTED result.

               
  • Anonymous
    August 21, 2006
    Set RightToLeft to True ( you must work in RTL environment though ), leave the textbox read-only, and turn alignment to the Right, and you'll get another "nice" one...