FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Error con ADO y XBrowse en recurso (Solucionado)
Posts: 1344
Joined: Wed Nov 16, 2005 09:14 PM
Error con ADO y XBrowse en recurso (Solucionado)
Posted: Wed May 22, 2013 03:08 PM
Estimados:
Estoy queriendo mostrar una consulta en un Xbrowse que defino en un recurso, pero me da un error. La misma consulta si la muestro con la funci贸n xbrowse funciona correctamente.
Seguramente algo b谩sico estoy haciendo mal porque estoy comenzando con esto, por eso recurro a la buena predisposici贸n del foro.
Code (fw): Select all Collapse
oRs := TOleAuto():New("ADODB.Recordset")
oRs:Open(cSql,oCn)
DEFINE WINDOW oWnd1 MDICHILD TITLE "RESULTADO DE LA CONSULTA" OF oWnd NOZOOM ICON oIco
聽 聽 聽 聽 聽DEFINE BUTTONBAR oBar 聽SIZE 60,60 OF oWnd1 2010
聽 聽 聽 聽 聽DEFINE BUTTON RESOURCE "EXCE" OF oBar 聽 TOOLTIP "Exportar a Excel" 聽;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 ACTION oBrw:ToExcel() 聽PROMPT "Exporta" TOP
聽 聽 聽 聽 聽DEFINE BUTTON RESOURCE "IMPR" OF oBar TOOLTIP "Imprimir Planilla" 聽;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 ACTION oBrw:Report("Reporte",.T.,.F.) PROMPT "Reporte" TOP
聽 聽 聽 聽 聽DEFINE BUTTON RESOURCE "SALE" OF oBar TOOLTIP "Cerrar Ventana" ;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 ACTION oWnd1:End() 聽PROMPT "Cerrar" TOP
聽 聽oWnd1:bGotFocus := { || oDlg:SetFocus}
聽 聽oWnd1:bResized := { || Incrusta( oWnd1, oDlg, .t.) }
聽 聽 聽DEFINE DIALOG oDlg RESOURCE "ABMS" OF oWnd1
聽 聽 聽oBrw := TXBrowse():New()
聽 聽 REDEFINE XBROWSE oBrw ID 111 OF oDlg RECORDSET oRs 聽AUTOCOLS AUTOSORT CELL
聽 聽 聽// Activo el dialogo y al iniciar muevo a 0,0
聽 聽 聽ACTIVATE DIALOG oDlg NOWAIT ON INIT oDlg:Move(0,0)
聽 聽ACTIVATE WINDOW oWnd1 ON INIT Incrusta( oWnd1, oDlg, .T.)

El error que me genera al mostrar el dialogo es el siguiente
Code (fw): Select all Collapse
Application
===========
聽 聽Path and name: F:\ado.exe (32 bits)
聽 聽Size: 2,131,456 bytes
聽 聽Compiler version: Harbour 3.1.0dev (Rev. 17114)
聽 聽FiveWin 聽Version: FWH 11.11
聽 聽Windows version: 5.1, Build 2600 Service Pack 3

聽 聽Time from start: 0 hours 0 mins 51 secs 
聽 聽Error occurred at: 22/05/2013, 11:55:42
聽 聽Error description: (DOS Error -2147352567) WINOLE/1007 聽Argument error: RECORDCOUNT

Stack Calls
===========
聽 聽Called from: 聽=> TOLEAUTO:RECORDCOUNT( 0 )
聽 聽Called from: .\source\classes\XBROWSE.PRG => (b)TXBROWSE_SETADO( 4277 )
聽 聽Called from: .\source\classes\XBROWSE.PRG => TXBROWSE:PAINT( 1381 )
聽 聽Called from: .\source\classes\XBROWSE.PRG => TXBROWSE:DISPLAY( 1250 )
聽 聽Called from: .\source\classes\CONTROL.PRG => TCONTROL:HANDLEEVENT( 1665 )
聽 聽Called from: .\source\classes\XBROWSE.PRG => TXBROWSE:HANDLEEVENT( 11627 )
聽 聽Called from: .\source\classes\WINDOW.PRG => _FWH( 3169 )
聽 聽Called from: 聽=> SYSREFRESH( 0 )
聽 聽Called from: .\source\classes\DIALOG.PRG => TDIALOG:END( 508 )
聽 聽Called from: .\source\function\ERRSYSW.PRG => (b)ERRORDIALOG( 407 )
聽 聽Called from: .\source\classes\BUTTON.PRG => TBUTTON:CLICK( 157 )
聽 聽Called from: .\source\classes\CONTROL.PRG => TBUTTON:HANDLEEVENT( 1653 )
聽 聽Called from: .\source\classes\WINDOW.PRG => _FWH( 3169 )
聽 聽Called from: 聽=> SENDMESSAGE( 0 )
聽 聽Called from: .\source\classes\DIALOG.PRG => TDIALOG:COMMAND( 379 )
聽 聽Called from: 聽=> TWINDOW:HANDLEEVENT( 0 )
聽 聽Called from: .\source\classes\DIALOG.PRG => TDIALOG:HANDLEEVENT( 882 )
聽 聽Called from: 聽=> DIALOGBOXINDIRECT( 0 )
聽 聽Called from: .\source\classes\DIALOG.PRG => TDIALOG:ACTIVATE( 270 )
聽 聽Called from: .\source\function\ERRSYSW.PRG => ERRORDIALOG( 426 )
聽 聽Called from: .\source\function\ERRSYSW.PRG => (b)ERRORSYS( 31 )
聽 聽Called from: 聽=> TOLEAUTO:RECORDCOUNT( 0 )
聽 聽Called from: .\source\classes\XBROWSE.PRG => (b)TXBROWSE_SETADO( 4277 )
聽 聽Called from: .\source\classes\XBROWSE.PRG => TXBROWSE:PAINT( 1381 )
聽 聽Called from: .\source\classes\XBROWSE.PRG => TXBROWSE:DISPLAY( 1250 )
聽 聽Called from: .\source\classes\CONTROL.PRG => TCONTROL:HANDLEEVENT( 1665 )
聽 聽Called from: .\source\classes\XBROWSE.PRG => TXBROWSE:HANDLEEVENT( 11627 )
聽 聽Called from: .\source\classes\WINDOW.PRG => _FWH( 3169 )
聽 聽Called from: 聽=> DIALOGBOXINDIRECT( 0 )
聽 聽Called from: .\source\classes\DIALOG.PRG => TDIALOG:ACTIVATE( 270 )
聽 聽Called from: .\source\function\ERRSYSW.PRG => ERRORDIALOG( 426 )
聽 聽Called from: .\source\function\ERRSYSW.PRG => (b)ERRORSYS( 31 )
聽 聽Called from: 聽=> TOLEAUTO:RECORDCOUNT( 0 )
聽 聽Called from: .\source\classes\XBROWSE.PRG => (b)TXBROWSE_SETADO( 4277 )
聽 聽Called from: .\source\classes\XBROWSE.PRG => TXBROWSE:PAINT( 1381 )
聽 聽Called from: .\source\classes\XBROWSE.PRG => TXBROWSE:DISPLAY( 1250 )
聽 聽Called from: .\source\classes\CONTROL.PRG => TCONTROL:HANDLEEVENT( 1665 )
聽 聽Called from: .\source\classes\XBROWSE.PRG => TXBROWSE:HANDLEEVENT( 11627 )
聽 聽Called from: .\source\classes\WINDOW.PRG => _FWH( 3169 )
聽 聽Called from: 聽=> WINRUN( 0 )
聽 聽Called from: .\source\classes\WINDOW.PRG => TMDIFRAME:ACTIVATE( 990 )
聽 聽Called from: ADO.prg => MAIN( 51 )


Gracias de antemano por su colaboraci贸n
Posts: 2170
Joined: Fri Jul 18, 2008 01:24 AM
Re: Error con ADO y XBrowse en recurso
Posted: Wed May 22, 2013 06:38 PM

Hola cmsoft, intenta omitiendo esta linea: //oBrw := TXBrowse():New()

Francisco J. Alegr铆a P.

Chinandega, Nicaragua.



Fwxh-MySql-TMySql
Posts: 1344
Joined: Wed Nov 16, 2005 09:14 PM
Re: Error con ADO y XBrowse en recurso
Posted: Wed May 22, 2013 07:59 PM

Gracias por responder Francisco.
Esa linea la tengo comentada, copie mal ac谩, pero igual da el mismo error.

Posts: 1344
Joined: Wed Nov 16, 2005 09:14 PM
Re: Error con ADO y XBrowse en recurso
Posted: Thu May 23, 2013 01:15 PM
La solucion estaba en el foro!!!

Code (fw): Select all Collapse
 聽// Defino el dialogo tomado del recurso ABMCAJA
聽 聽DEFINE WINDOW oWnd1 MDICHILD TITLE "RESULTADO DE LA CONSULTA" ;
聽 聽 聽 聽 聽 OF oWnd NOZOOM ICON oIco
聽 聽 聽 聽 聽DEFINE BUTTONBAR oBar 聽SIZE 60,60 OF oWnd1 2010
聽 聽 聽 聽 聽DEFINE BUTTON RESOURCE "EXCE" OF oBar ;
聽 聽 聽 聽 聽 聽 TOOLTIP "Exportar a Excel" ;
聽 聽 聽 聽 聽 聽 ACTION oBrw:ToExcel() ;
聽 聽 聽 聽 聽 聽 PROMPT "Exporta" TOP
聽 聽 聽 聽 聽DEFINE BUTTON RESOURCE "IMPR" OF oBar ;
聽 聽 聽 聽 聽 聽 TOOLTIP "Imprimir Planilla" 聽;
聽 聽 聽 聽 聽 聽 ACTION oBrw:Report("Reporte",.T.,.F.);
聽 聽 聽 聽 聽 聽 PROMPT "Reporte" TOP
聽 聽 聽 聽 聽// Este boton cierra la aplicacion
聽 聽 聽 聽 聽DEFINE BUTTON RESOURCE "SALE" OF oBar;
聽 聽 聽 聽 聽 聽 TOOLTIP "Cerrar Ventana" ;
聽 聽 聽 聽 聽 聽 ACTION oWnd1:End();
聽 聽 聽 聽 聽 聽 PROMPT "Cerrar" TOP
聽 聽DEFINE DIALOG oDlg RESOURCE "ABMS" OF oWnd1 聽 聽 聽 聽 聽 聽 聽 
聽 聽oWnd1:bGotFocus := { || oDlg:SetFocus}
聽 聽oWnd1:bResized := { || Incrusta( oWnd1, oDlg, .t.) }
聽 聽oBrw := TXBrowse():New( oDlg ) 
聽 聽oBrw:SetAdo(oRs,.T.,.T.)
聽 聽oBrw:nMarqueeStyle 聽 聽 聽 := MARQSTYLE_HIGHLCELL 
聽 聽oBrw:nColDividerStyle 聽 聽:= LINESTYLE_BLACK 
聽 聽oBrw:nRowDividerStyle 聽 聽:= LINESTYLE_BLACK 
聽 聽oBrw:lColDividerComplete := .t. 
聽 聽oBrw:CreateFromResource(111)
聽 // Activo el dialogo y al iniciar muevo a 0,0
聽 聽ACTIVATE DIALOG oDlg NOWAIT ON INIT oDlg:Move(0,0) 聽CENTER 
ACTIVATE WINDOW oWnd1 ON INIT Incrusta( oWnd1, oDlg, .T.) Valid( oRs:Close() = nil)
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Error con ADO y XBrowse en recurso (Solucionado)
Posted: Thu May 23, 2013 01:57 PM
Parece un error de la gesti贸n de objetos OLE de Harbour, de lo que ser铆a aconsejable que pruebes con la versi贸n m谩s reciente de Harbour y FWH

F铆jate que el sistema de errores de OLE dice que se le ha suministrado un par谩metro err贸neo a RecordCount pero desde el c贸digo no se le ha pasado ning煤n par谩metro. De ahi. el suponer que el fallo viene de la versi贸n de Harbour usada.

Supongo que estas usando la clase xbrowse original de FWH y que no la has modificado, por lo que recordcount() no recibe par谩metros. Revisa xbrowse.prg y busca por recordcount

Error description: (DOS Error -2147352567) WINOLE/1007 Argument error: RECORDCOUNT // aqui indica de un error de par谩metro

Stack Calls
===========
Called from: => TOLEAUTO:RECORDCOUNT( 0 ) // el cero significa que no se han usado par谩metros
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Error con ADO y XBrowse en recurso (Solucionado)
Posted: Fri May 24, 2013 05:19 AM
Another suggestion:

The errir
Code (fw): Select all Collapse
Called from: 聽=> TOLEAUTO:RECORDCOUNT( 0 )

arises when oRs is closed when the browse is trying to paint.

In case of MDICHILD windows, it is advised to close oRs in oWnd:bPostEnd codeblock, but not in VALID clause.

oWnd:bPostEnd := { || oRs:Close() }.
This is the safest way to avoid such errors.
Also we need to make sure that we are not closing the oRs elsewhere in the program by mistake.
Regards



G. N. Rao.

Hyderabad, India
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: Error con ADO y XBrowse en recurso (Solucionado)
Posted: Fri May 24, 2013 01:12 PM
Rao is correct .. this particular error drives me nuts from time to time ..


Stack Calls
===========
Called from: => TOLEAUTO:RECORDCOUNT( 0 )
Called from: .\source\classes\XBROWSE.PRG => (b)TXBROWSE_SETADO( 4277 )
Called from: .\source\classes\XBROWSE.PRG => TXBROWSE:PAINT( 1381 )
Called from: .\source\classes\XBROWSE.PRG => TXBROWSE:DISPLAY( 1250 )
Called from: .\source\classes\CONTROL.PRG => TCONTROL:HANDLEEVENT( 1665 )
Called from: .\source\classes\XBROWSE.PRG => TXBROWSE:HANDLEEVENT( 11627 )
Called from: .\source\classes\WINDOW.PRG => _FWH( 3169 )
Called from: => SYSREFRESH( 0 )



Here is a sample of my Mdi\Child valid close .. note the code blocks

oLbxA:bKeyCount := { || 0 }
oLbxA:bKeyNo := { || 0 }

Code (fw): Select all Collapse
//---------------------------------------------
Static FUNCTION ExitPgm( lOk3,oWndChildA,oWndCHild,oLbxA,lOk,;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽oLbx,oFontB,oFontB1,oRsSch,oWndChildB,lOpen,oRsRepair 聽)

LOCAL lOK1

*Msginfo( "ExitPgm 聽closing schedule")
*msginfo( "Value of oWndChildB")
*msginfo( oWndChildB )


IF lOk3 = .T.
聽 聽lOK 聽:= .T.
聽 聽lOK1 := lOK

聽 聽Try
聽 聽 聽 oWndChildB:end()
聽 聽Catch
聽 聽End Try

聽 聽oRsSch:CLose()
聽 聽oRsSch := NIL

聽 聽If lOpen = .t. 聽 聽 聽 聽 聽 聽 // t = had to open from main
聽 聽 聽 oRsRepair:CLose() 聽 // f = came from workbrow
聽 聽 聽 oRsRepair := nil
聽 聽Endif

聽 聽oLbxA:bKeyCount := { || 0 } 聽 
聽 聽oLbxA:bKeyNo 聽 聽:= { || 0 }

聽 聽oFontB:End()
聽 聽oFontB1:End()

聽 聽If lOpen = .f.
聽 聽 聽 oWndChild:Show()

聽 聽 聽 oLbx:ReFresh()
聽 聽 聽 oLbx:SetFocus()
聽 聽ENdif

ENDIF

RETURN( lOK1 )


Second suggestion is to NOT use SysReFresh() anywhere in your xBrowse code .. even a debugging MsgINfo() contains an embeded SysRefresh() that will cause your run-time error.


Stack Calls
===========
Called from: => TOLEAUTO:RECORDCOUNT( 0 )
Called from: .\source\classes\XBROWSE.PRG => (b)TXBROWSE_SETADO( 4277 )
Called from: .\source\classes\XBROWSE.PRG => TXBROWSE:PAINT( 1381 )
Called from: .\source\classes\XBROWSE.PRG => TXBROWSE:DISPLAY( 1250 )
Called from: .\source\classes\CONTROL.PRG => TCONTROL:HANDLEEVENT( 1665 )
Called from: .\source\classes\XBROWSE.PRG => TXBROWSE:HANDLEEVENT( 11627 )
Called from: .\source\classes\WINDOW.PRG => _FWH( 3169 )
Called from: => SYSREFRESH( 0 )



Rick Lipkin
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Error con ADO y XBrowse en recurso (Solucionado)
Posted: Fri May 24, 2013 03:00 PM

Mr Rick

As I suggested, please close oRs only in oWnd:bPostEnd codeblock and then forget all about the problem.

Clarification:
bValid is executed prior to closing the window. At that time Browse and all other controls are still alive. It is possible that any of them need to be repainted. Then this error occurs.

bPostEnd is executed after the window is closed and all controls are destroyed. If the oRs is closed at that time, there is no control requiring access to the oRs.

Same is the case with closing DBFs also.

Regards



G. N. Rao.

Hyderabad, India
Posts: 3358
Joined: Fri Oct 07, 2005 08:20 PM
Re: Error con ADO y XBrowse en recurso (Solucionado)
Posted: Fri May 24, 2013 05:03 PM
Friends:

I do that in this way and not problem at all:

Code (fw): Select all Collapse
ACTIVATE WINDOW oWnd ON INIT ....聽 聽VALID CloseRS()
RETURN (NIL)

/*
* --------------------------------------------------------------------------*
* --------------------------------------------------------------------------*
*/
STATIC FUNCTION CloseRS()
聽 聽 oWnd聽 聽 聽 聽 := NIL
聽 聽 IF oRsMyRs <> NIL
聽 聽 聽 聽 IF oRsMyRs:State() = adStateOpen
聽 聽 聽 聽 聽 聽 oRsMyRs:Close()
聽 聽 聽 聽 ENDIF
聽 聽 ENDIF
RETURN(.T.)


Regards
SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: Error con ADO y XBrowse en recurso (Solucionado)
Posted: Fri May 24, 2013 05:24 PM
Rao

I like your solution .. and I totally agree with you.. but where would you place the
Code (fw): Select all Collapse
oWnd:bPostEnd := { || oRs:Close() }.


right after the oWnd:CLose() ?
Code (fw): Select all Collapse
oWnd:CLose() 
oWnd:bPostEnd := { || oRs:Close() }.


Thanks
Rick Lipkin
Posts: 1344
Joined: Wed Nov 16, 2005 09:14 PM
Re: Error con ADO y XBrowse en recurso (Solucionado)
Posted: Fri May 24, 2013 08:28 PM

Gracias a todos por las respuestas y sugerencias!
Me quedo con la soluci贸n de poner oWnd:bPostEnd := { || oRs:Close() }
Muchas gracias!

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Error con ADO y XBrowse en recurso (Solucionado)
Posted: Fri May 24, 2013 10:43 PM
I like your solution .. and I totally agree with you.. but where would you place the

Anywhere before ACTIVATE WINDOW oWnd
Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Error con ADO y XBrowse en recurso (Solucionado)
Posted: Fri May 24, 2013 10:46 PM

Mr Armando

Closing recset or dbf in VALID clause normally works. But it is not in our control when a control of the window tries to access recset/dbf after execution of valid statement and before destruction of the control.

So, it is safe to close recset / dbf in the oWnd:bPostEnd codeblock.

Regards



G. N. Rao.

Hyderabad, India
Posts: 3358
Joined: Fri Oct 07, 2005 08:20 PM
Re: Error con ADO y XBrowse en recurso (Solucionado)
Posted: Sat May 25, 2013 05:42 PM

Mr. Rao:

I understood, thanks.

Regards

SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero

Continue the discussion