FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour xBrowse Editing Error - numeric values rounding
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
xBrowse Editing Error - numeric values rounding
Posted: Fri Aug 30, 2013 09:40 PM
In a file editor class, the following function is used to edit a single record from a file:

Code (fw): Select all Collapse
METHOD EditRec(  ) CLASS MLSEditor

  MEMVAR oBrush, oMFont
  
  LOCAL aEdits := {}, n, nCcol, oHd2
  LOCAL oERecEdt, oERec, lSaveEdits := .f.
  
  FOR n := 1 TO LEN( ::oDbfr:aBuffer )
    AADD( aEdits, { ::oBrw:aCols[n]:cHeader, ::oDbfr:aBuffer[n] } )
  NEXT
   
        // Create the dialog
        DEFINE DIALOG oERec RESOURCE "PROBROW" BRUSH oBrush transparent OF ::oEWndChild TITLE "Record Edit" FONT oMFont

        // Create the control buttons
        REDEFINE BTNBMP RESOURCE "HREXIT" PROMPT "Exit Edit" ID 2101 of oERec NOBORDER TRANSPARENT ;
             ACTION  oERec:end() 
        REDEFINE BTNBMP RESOURCE "HRSAVE" PROMPT "Save & Exit" ID 2102 of oERec NOBORDER TRANSPARENT ;
           ACTION lSaveEdits := .t., oERec:end( )
        REDEFINE BUTTON oHd2 ID 2103 of oERec

        // Create the browse
        REDEFINE XBROWSE  oERecEdt ID 2100 OF oERec  

        // Attach the array
        oERecEdt:setArray( aEdits )
        oERecEdt:aCols := {}

        // Add the columns
        ADD TO oERecEdt DATA ARRAY ELEMENT 1 HEADER "Fields" SIZE 100 ALIGN LEFT
        ADD TO oERecEdt DATA ARRAY ELEMENT 2 HEADER "Data" EDITABLE SIZE 300 ALIGN LEFT

        // Provide the header gradient
        oERecEdt:bClrGrad := { | lInvert | If( ! lInvert, { { 0.50,16776960,16777215 }, ;
            { 0.50,16777215,16776960 } }, { { 0.50,128,16777215 }, { 0.50,16777215,128 } } ) }
        // Set the header and row heights
        oERecEdt:nHeaderHeight := 30
        oERecEdt:nRowHeight := 24
        oERecEdt:nStretchCol( STRETCHCOL_WIDEST )

        // Turn off horizontal scrolling
        oERecEdt:lHScroll := .F.

        // Set the styles
        oERecEdt:nMarqueeStyle := MARQSTYLE_HIGHLROW
        oERecEdt:nColDividerStyle := LINESTYLE_RAISED
        oERecEdt:nRowDividerStyle := LINESTYLE_RAISED
        FOR nCCol := 1 TO LEN( oERecEdt:acols )
            oERecEdt:aCols[nCCol]:nHeadStrAlign  := AL_CENTER
        NEXT

        // Activate the dialog
        ACTIVATE DIALOG oERec ON INIT ( oHd2:hide( ), oERec:center(wndmain()) )

    // If we wish to save the values    
    IF lSaveEdits := .t.

      FOR n := 1 TO LEN( aEdits )
    ::oDbfr:aBuffer[n] := aEdits[n,2]
     NEXT
     ::oDbfr:save()

  ENDIF
   
RETURN NIL


Here is how it works. An xBrowse displays all the records of a database, and the values of the record in focus is saved in a database record object ( oDbfr ). When the edit is called, the field names and values are loaded into a two element array, and then placed into an xBrowse control. The second column ( value ) is editable. If the edits are saved, the values are written to the record which is saved and all is fine.

Here is the problem: This works perfectly with xHarbour ( .com ) / Pelles C. However, with Harbour / MSVC, if the value is numeric ( decimal ), it rounds off the value. Thus, 12.68 would be set as 13.

Perhaps someone can give me a hint on why the two different behaviors based on compiler ? How do we fix it ?

Tim
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: xBrowse Editing Error - numeric values rounding
Posted: Tue Sep 03, 2013 03:46 PM

Perhaps with a new title, someone will actually respond to this question ?

Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: xBrowse Editing Error - numeric values rounding
Posted: Tue Sep 03, 2013 09:03 PM

Tim,

I don't know why this is happening, but have you tried:

SET FIXED ON
SET DECIMAL TO 2

I know that is supposed to be the default, but maybe the preprocessor is messing something up.

Try making as small of a program as you can showing the problem--just create an array of a couple of items and a browse to edit it. This will make it easier for others to try to fix it.

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: xBrowse Editing Error - numeric values rounding
Posted: Tue Sep 03, 2013 09:07 PM

James,

This is probably the only code I have that is actually allowing an edit in xBrowse.

It may help to note that the error only occurs with Harbour / MSVC, and is fine with xHarbour / Pelles C builds.

It may be that Antonio made a change in a build that he did not include in the Microsoft libraries he creates.

Tim

Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: xBrowse Editing Error - numeric values rounding
Posted: Tue Sep 03, 2013 10:08 PM

Tim,

Still, a small self-contained program would make it easier for Antonio to check and fix.

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: xBrowse Editing Error - numeric values rounding
Posted: Tue Sep 03, 2013 11:44 PM
James,

Here is a cut down that makes it rather straight forward:

Code (fw): Select all Collapse
METHOD TestEditRec(  ) CLASS MLSEditor

  MEMVAR oBrush, oMFont
  
  LOCAL aEdits := {}, n, nCcol, oHd2
  LOCAL oERecEdt, oERec, lSaveEdits := .f.
  
  AADD( aEdits, { "C", "String" } )
  FOR n := 1 TO 3
    AADD( aEdits, { "N", 12.80 } )
  NEXT
  AADD( aEdits, { "C", "String" } )  
   
        // Create the dialog
        DEFINE DIALOG oERec RESOURCE "PROBROW" BRUSH oBrush transparent OF ::oEWndChild TITLE "Record Edit" FONT oMFont

        // Create the control buttons
        REDEFINE BTNBMP RESOURCE "HREXIT" PROMPT "Exit Edit" ID 2101 of oERec NOBORDER TRANSPARENT ;
             ACTION  oERec:end() 
        REDEFINE BTNBMP RESOURCE "HRSAVE" PROMPT "Save & Exit" ID 2102 of oERec NOBORDER TRANSPARENT 

        // Create the browse
        REDEFINE XBROWSE  oERecEdt ID 2100 OF oERec  

        // Attach the array
        oERecEdt:setArray( aEdits )
        oERecEdt:aCols := {}

        // Add the columns
        ADD TO oERecEdt DATA ARRAY ELEMENT 1 HEADER "Fields" SIZE 100 ALIGN LEFT
        ADD TO oERecEdt DATA ARRAY ELEMENT 2 HEADER "Data" EDITABLE SIZE 300 ALIGN LEFT

        // Turn off horizontal scrolling
        oERecEdt:lHScroll := .F.

        // Activate the dialog
        ACTIVATE DIALOG oERec ON INIT ( oHd2:hide( ), oERec:center(wndmain()) )
 
RETURN NIL


Here is the browse code from the .rc file:

Code (fw): Select all Collapse
PROBROW DIALOG DISCARDABLE 0, 0, 500, 240
STYLE WS_POPUP|DS_MODALFRAME|WS_CAPTION|WS_VISIBLE
CAPTION "Look-Up Chart"
FONT 12, "Segoe UI"
BEGIN
  CONTROL "", 2100, "TXBrowse", WS_TABSTOP|0x00a00000, 10,10, 430, 230
  CONTROL "", 2103, "Button", WS_TABSTOP, 450, 20, 40, 40
  CONTROL "", 2101, "Button", WS_TABSTOP, 450, 80, 40, 40
  CONTROL "", 2102, "Button", WS_TABSTOP, 450, 140, 40, 40
END


If works fine with xHarbour / Pelles C, but doesn't allow the numbers past the decimal with Harbour / MSVC 2012.

Tim
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: xBrowse Editing Error - numeric values rounding
Posted: Wed Sep 04, 2013 07:18 AM
Good that you pointed this out.
I have reduced your sample to this following code.
Code (fw): Select all Collapse
function xbrnumedit()

   local aData := { { "C", "String" }, { "N", 27 }, { "N", 12.34 }, { "C", "STRING" } }

   XBROWSER aData FASTEDIT

   ? adata[2,2],adata[3,2]

return nil

With xHarbour, any version, you can edit the third line with decimal places and decimal value is retained.
With present versions of Harbour ( I have no idea about earlier versions) we can not edit the 3d line after decimals and the value is rounded to integer after editing.
I do not say that there is any problem with Harbour. It is just that xbrowse's edit of numerics without picture clause is behaving diferently with xHarbour and Harbour. I am looking into xbrowse code and yet to come up with a satisfactory answer.

Meanwhile I suggest a workaround to conditionally use picture clause for numeric values. I shall post this code soon.

Please give us a little more time.
Regards



G. N. Rao.

Hyderabad, India
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: xBrowse Editing Error - numeric values rounding
Posted: Wed Sep 04, 2013 03:51 PM

I use this code in a record editor. The left column ( element 1 of the array ) is a field name.

The 2nd column ( EDITABLE ) is a value, and it could be of any data type. Thus, I couldn't set the column with a picture clause because sometimes the value is a string, or a date, or a decimal.

Thanks for looking into this.

Tim

Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: xBrowse Editing Error - numeric values rounding
Posted: Fri Sep 06, 2013 10:41 PM

Mr. Rao,

I just wanted to keep this on top since you said you would be addressing the issue.

Your help is greatly appreciated.

Tim Stone

Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: xBrowse Editing Error - numeric values rounding
Posted: Wed Sep 11, 2013 07:01 AM
I would call this a workaround rather than 'fix'. But this works for the time being.
Please locate the line
Code (fw): Select all Collapse
::oEditGet := TGet():New( 0,0,{ | u | If(PCount()==0,uValue,uValue:= u ) },;

in METHOD Edit( nKey ) CLASS TXBrwColumn.

Just above this line, please insert
Code (fw): Select all Collapse
#ifndef __XHARBOUR__
         if Empty( cPic ) .and. ValType( uValue ) == 'N'
            cPic     := NumPict( ::nWidthChr, Len( AfterAtNum( '.', cValToChar( uValue ) ) ) )
         endif
#endif

We are adopting this workaround for the 13.08 release.
When we find and fix the exact reason for difference in behavior between harbour and xharbour, we my remove this workaround.
Regards



G. N. Rao.

Hyderabad, India
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: xBrowse Editing Error - numeric values rounding
Posted: Wed Sep 11, 2013 03:41 PM

Thank you. That resolves the problem.

Tim

Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit

Continue the discussion