FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour xBrowse with ADO
Posts: 842
Joined: Mon Oct 10, 2005 01:29 PM
xBrowse with ADO
Posted: Thu Nov 27, 2014 10:23 AM
Mr Nages,

I have a xBrowse
I need switching Recordset dynamically ,and the table and fields of the recordset are not identical.

I solved in this way

Open new Recset oNewRs
FOR i := len(oBrwLis:aCols) to 1 STEP - 1
oBrw:DelCol(i)
NEXT

oBrw:SetADO( oNewRs )
oRsOld:Close()
oBrw:GoTop()
oBrw:Refresh()

Is correct use oBrw:SetADO( oNewRs ) or can cause side effects ?

I have another question
In the xBrowse I have logical columns : COL_1 , COL_2,...

I do not understand why this works
Code (fw): Select all Collapse
FOR nX := 1 TO len(oBrw:aCols) 
    WITH OBJECT oBrw:aCols[nX]
        :SetCheck() 
        :bStrData := { || ""   }
        IF :cExpr == "COL_1"
           :bEditValue := { || IF(  oBrw:oRs:Fields("COL_1" ) :Value   == -1 ,.T.,.F.) }
        ENDIF  
        IF :cExpr == "COL_2"
          :bEditValue := { || IF(  oBrw:oRs:Fields("COL_2" ) :Value   == -1 ,.T.,.F.) }
        ENDIF  
    END
NEXT


and this dosn't work
Code (fw): Select all Collapse
FOR nX := 1 TO len(oBrw:aCols) 
    WITH OBJECT oBrw:aCols[nX]
        :SetCheck() 
        :bStrData := { || ""   }
        
        :bEditValue := { || IF(  oBrw:oRs:Fields(:cExpr) :Value   == -1 ,.T.,.F.) }
        
        
    END
NEXT



Thanks in anticipation
Maurizio
http://www.nipeservice.com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: xBrowse with ADO
Posted: Sun Nov 30, 2014 03:43 AM

You can simply assign new RecSet object if the field structures are identical. XBrowse is designed for this, provided you do not directly use the recset object in your code.

But xbrowse is not designed to handle replacing RecSet with totally a different field structure.
I personally prefer is to create new Browse and switch the browses. This is what I do in my own applications.

However you may try the approach you proposed with these modifications:

  1. delete all columns as in your code.
    then
    oBrw:lAdjusted := .f. // new
    oBrw:SetADO( oRsNew ) // You may use last param aFldNames if you want specific fields

// Here you insert other code like changing bEditValue, SetCheck() etc.

Finally,
oBrw:Adjust() // new

I like your feedback.

About setcheck():
First change the bEditValue to return logical value, set oCol:cDataType := 'L' and then call SetCheck()
You do not touch bStrData ( difference from older versions)

WITH OBJECT oCol
:bEditValue := { ............}
:cDataType := 'L'
:SetCheck()
END

The reason for your second code not working is that you can not use loop based variables in building a codeblock within a loop.
Instead try:
:bEditValue := { |x,o| oBrw:oRs:Fields(o:cExpr) :Value == -1 }

Still this makes the column readonly. Make it read/write by
:bEditValue := { |x,o| If( x == nil, oBrw:oRs:Fields(o:cExpr):Value == -1, ;
oBrw:oRs:Fields(o:cExpr):Value := If( x, -1, 0 ) ) }

Regards



G. N. Rao.

Hyderabad, India
Posts: 842
Joined: Mon Oct 10, 2005 01:29 PM
Re: xBrowse with ADO
Posted: Mon Dec 01, 2014 01:52 PM
Thanks Mr Nages,

I followed your advice and it works.

I checked the memory usage and I noted that memory increase.
I created this sample using a classic xbrowse with DBF (I know it is exaggerated) .
Code (fw): Select all Collapse
#include 'fivewin.ch'
#include 'xbrowse.ch'

Static oBrw,oDlg 
function Main()

   local oDlg, oBrw, oFont
   local oCol
   local n := RGB( 157, 248, 255 )

   XbrNumFormat( 'E', .t. )
  
   USE CUSTOMER ALIAS CUST

   DEFINE FONT oFont NAME 'Tahoma' SIZE 0,-14
   DEFINE DIALOG oDlg SIZE 640,440 PIXEL ;
      FONT oFont TITLE 'XBrowse Gradient Rows FWH 9.12'

  DoBrowse()

   oDlg:bStart := {|| BuildTimer() }

   ACTIVATE DIALOG oDlg CENTERED 

   CLOSE CUST
   RELEASE FONT oFont

return nil

//-------------------------------------------------------------------------------------------
Function DoBrowse()


   @ 10,10 XBROWSE oBrw OF oDlg ;
      SIZE -10,-10 PIXEL ;
      COLUMNS 'FIRST', 'HIREDATE', 'MARRIED', 'SALARY' ;
      ALIAS 'CUST' LINES NOBORDER


   WITH OBJECT oBrw
      :nStretchCol   := 1
      :nMarqueeStyle := 4
   END

   oBrw:CreateFromCode()




Return nil 

//-------------------------------------------------------------------------------------------
Static Function BuildTimer()

  local oTimer
 
   DEFINE TIMER oTimer INTERVAL 50 ;
                ACTION ( oTimer:deactivate(),;
                         oBrw:End(),oBrw:= nil,DoBrowse(),;
                         oTimer:activate()) OF oDlg

   
   ACTIVATE TIMER oTimer
 
 
 Return NIL

The program crash after 30/60 minutes (depends to PC memory)
with Unrecoverable error 9006: hb_xgrab can't allocate memory .
Fivewin dosn't return any messagge , harbour get hb_out.log
Code (fw): Select all Collapse
Application Internal Error - C:\FWH_09\samples\xb.exe
Terminated at: 2014-12-01 14:47:28
Unrecoverable error 9006: hb_xgrab can't allocate memory
Called from __CLSINST(0)
Called from HBCLASS:INSTANCE(0) in ../../../tclass.prg
Called from TXBROWSE(128) in .\source\classes\XBROWSE.PRG
Called from (b)TXBROWS(13245) in .\source\classes\XBROWSE.PRG
Called from TXBROWS(13255) in .\source\classes\XBROWSE.PRG
Called from XBROWSENEW(12788) in .\source\classes\XBROWSE.PRG
Called from DOBROWSE(37) in XB.prg
Called from (b)BUILDTIMER(60) in XB.prg
Called from TIMEREVENT(73) in .\source\classes\TIMER.PRG
Called from (b)TWINDOW(644) in .\source\classes\WINDOW.PRG
Called from TDIALOG:TIMER(0) in .\source\classes\WINDOW.PRG
Called from TWINDOW:HANDLEEVENT(0)
Called from TDIALOG:HANDLEEVENT(903) in .\source\classes\DIALOG.PRG
Called from DIALOGBOXINDIRECT(0)
Called from TDIALOG:ACTIVATE(283) in .\source\classes\DIALOG.PRG
Called from MAIN(23) in XB.prg
------------------------------------------------------------------------


I use : FWH_09 , Harbour , BCC

Regards Maurizio
www.nipeservice.com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: xBrowse with ADO
Posted: Mon Dec 01, 2014 02:49 PM

Each time DoBrowse() is executed, the new oBrw is added to oDlg:aControls array and this array keeps bloating till memory gets exhausted.

Please try inserting oDlg:aControls := {} before defining browse in DoBrowse()

Regards



G. N. Rao.

Hyderabad, India
Posts: 842
Joined: Mon Oct 10, 2005 01:29 PM
Re: xBrowse with ADO
Posted: Mon Dec 01, 2014 04:44 PM

Hello
I try oDlg:aControls := {} same problem , I verified the len(oDlg:aControls) and remain the same .

Regards
Maurizio

Continue the discussion