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