xBrowse Editing Error - numeric values rounding

xBrowse Editing Error - numeric values rounding

Postby TimStone » Fri Aug 30, 2013 9:40 pm

In a file editor class, the following function is used to edit a single record from a file:

Code: Select all  Expand view

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
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: xBrowse Editing Error - numeric values rounding

Postby TimStone » Tue Sep 03, 2013 3: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
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: xBrowse Editing Error - numeric values rounding

Postby James Bott » Tue Sep 03, 2013 9: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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: xBrowse Editing Error - numeric values rounding

Postby TimStone » Tue Sep 03, 2013 9: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
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: xBrowse Editing Error - numeric values rounding

Postby James Bott » 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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: xBrowse Editing Error - numeric values rounding

Postby TimStone » Tue Sep 03, 2013 11:44 pm

James,

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

Code: Select all  Expand view


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: Select all  Expand view

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
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: xBrowse Editing Error - numeric values rounding

Postby nageswaragunupudi » Wed Sep 04, 2013 7:18 am

Good that you pointed this out.
I have reduced your sample to this following code.
Code: Select all  Expand view
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
User avatar
nageswaragunupudi
 
Posts: 10641
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: xBrowse Editing Error - numeric values rounding

Postby TimStone » Wed Sep 04, 2013 3: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
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: xBrowse Editing Error - numeric values rounding

Postby TimStone » 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
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: xBrowse Editing Error - numeric values rounding

Postby nageswaragunupudi » Wed Sep 11, 2013 7:01 am

I would call this a workaround rather than 'fix'. But this works for the time being.
Please locate the line
Code: Select all  Expand view
::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: Select all  Expand view
#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
User avatar
nageswaragunupudi
 
Posts: 10641
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: xBrowse Editing Error - numeric values rounding

Postby TimStone » Wed Sep 11, 2013 3: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
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 56 guests