FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour ToCalc() Method to transfer xBrowse Data to OpenOffice Calc
Posts: 682
Joined: Tue Feb 14, 2006 09:48 AM

Re: ToCalc() Method to transfer xBrowse Data to OpenOffice Calc

Posted: Wed Feb 18, 2009 02:52 PM
I'm Trying to use method ToCalc, but when I invoque the method ToCalc, ocurs an error.
Application
===========
Path and name: G:\fwh\Biel\EA6DDlog\EA6DDlog.Exe (32 bits)
Size: 2,203,648 bytes
Time from start: 0 hours 0 mins 16 secs
Error occurred at: 18-02-09, 13:04:12
Error description: Error TOleAuto/65535 : TOLEAUTO:NEW
Args:
[ 1] = C Excel.Application

Stack Calls
===========
Called from: .\win_tole.prg => THROW(79)
Called from: => TOLEAUTO:NEW(252)
Called from: G:\fwh\Clases no modificadas\xbrowse.prg => SETEXCELLANGUAGE(5853)
Called from: => TXBRWCOLUMN:CLPTEXT(8139)

SetExcelLanguage() is called if nxlLangID= NIL, and this function try to create object "Excel.Application", if we are using Harbour and haven't Excel ocurs the present error. With xHarbour no error because of the TRY ... CATCH.
So we can add TRY ... CATCH if compiler is harbour.
Code (fw): Select all Collapse
#ifdef __XHARBOUR__
         TRY
            oExcel   := GetActiveObject( "Excel.Application" )
         CATCH
            TRY
               oExcel   := CreateObject( "Excel.Application" )
            CATCH
               nxlLangID := 0
               return nil
            END
         END
         lLocal  := .t.
#else
         TRY     //<============Biel
            oExcel   := TOLEAuto():New( "Excel.Application" )
         CATCH
            nxlLangID:=0
            RETURN NIL
         END
#endif

Or really if we are working with Open Office, usually we don't have Excel installed, so we can assign 0 to nxlLangID at the begin of method ToCalc.
Code (fw): Select all Collapse
METHOD ToCalc( bProgress, nGroupBy, nPasteMode, aSaveAs ) CLASS TXBrowse

   local oCalc, oDeskTop,oBook, oSheet, oWin, oLocal, oDispatcher
   local nCol, nXCol, oCol, cType, uValue
   local uBookMark, nRow
   local nDataRows
   local aCols
   local oClip, cText, nPasteRow, nStep, cFormat,cFileName,cURL,i
   local aTotals  := {}, lAnyTotals := .f. , aProp:={} , aOOFilters:={} , nPos, oCharLocale
   DEFAULT nPasteMode:=1
   DEFAULT aSaveAs:={}
   DEFAULT nxlLangId:=0  //<===Biel


Note to use TRY ... CATH in harbour
Code (fw): Select all Collapse
static bError
      #xcommand TRY              => bError := errorBlock( {|oErr| break( oErr ) } ) ;;
                                    BEGIN SEQUENCE
      #xcommand CATCH [<!oErr!>] => errorBlock( bError ) ;;
                                    RECOVER [USING <oErr>] <-oErr-> ;;
                                    errorBlock( bError )

Actually included in Fivewin.ch
Saludos desde Mallorca
Biel Maimó
http://bielsys.blogspot.com/
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM

Re: ToCalc() Method to transfer xBrowse Data to OpenOffice Calc

Posted: Thu Feb 19, 2009 09:43 AM
Dear Mr.Biel,

I have not tested the Method ToCalc() using Harbour and hence I did not receive this error. :-)

Your suggestion is good. As you pointed out, I think we should make the following updates in xBrowse.Prg

1) In the Function SetExcelLanguage( oExcel ) TRY CATCH for HARBOUR should be implemented while trying to create Excel Object, so that the program does not quit abnormaly. Line 5853
2) In the Method ToCalc Adding the following code in Line 5037
Code (fw): Select all Collapse
     DEFAULT nxlLangId:=0

3) Before leaving the Method ToCalc(), the value of nxlLangId should be made to NIL, so that it does not disturb ToExcel() in any way. (To be on the safer side) :-)

If TY CATCH works in HARBOUR then I also suggest that the TRY CATCH for HARBOUR should be implemented in the Method ToExcel() where we try to create Excel Object, so that the program does not quit abnormaly Line 4834

Explanation for point no.3:

nxlLangID is a STATIC variable, and through out the PRG SetExcelLanguage() is called like the way given below
Code (fw): Select all Collapse
   if nxlLangID == nil
      SetExcelLanguage()
   endif

A numeric value is assigned to nxlLangID inside the Fuction SetExcelLanguage() based on the Installed language.

Considering a situation that a PC has both Excel and Calc installed and the user want to use both the Methods ToExcel() and ToCalc(). In this situation if we assign a value 0 to nxlLangId, I dont know what will happen when the following code gets executed from Method ToExcel()
Code (fw): Select all Collapse
   if nxlLangID == nil
      SetExcelLanguage()
   endif


May be I am not very clear with the STATIC variable declared just after the #Include statement. I beleive the value of ststic variable will be in the memory until we quit xBrowse.

Mr.Antonio, Can I have your opinion on this, so that this can be updated in the next FWH build

Regards

Anser
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM

Re: ToCalc() Method to transfer xBrowse Data to OpenOffice Calc

Posted: Tue Feb 24, 2009 07:17 AM

Dear Mr.Antonio,

I have send an email to you. Hope you have received the same.

Regards

Anser

Continue the discussion