Very strange OLE-problem

Very strange OLE-problem

Postby driessen » Fri Jun 02, 2017 11:44 am

Hello,

I use this code :
Code: Select all  Expand view  RUN
PRIVATE CuWole1,CuDoc1

CuWole1 := TOleAuto():New("Word.Application") ; ENDIF
CuDoc1  := CuWole1:Documents:Open(TRIM(US->DRIVE_BWP) + cBest)
MsgInfo(CuDoc1)
In Windows 7, the msginfo returns "Object", as it should be.
In Windows 10 though, the msginfo returns "Array". This results in other errors while saving etc.

Anyone any idea why there is a difference?

Thanks.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Very strange OLE-problem

Postby karinha » Fri Jun 02, 2017 12:41 pm

Code: Select all  Expand view  RUN

#include "FiveWin.ch"

function Main()

   local oWnd, oActiveX

   oWord:=TOleAuto():New( "Word.Application" )
   oWord:Documents:Open( "C:\AUTOEXEC.BAT" )
   oWord:Visible := .f.
   oWord:WindowState := 0
   oWord:PrintOut()
   oWord:Quit()
   oWord:End()

return nil
 
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7855
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Very strange OLE-problem

Postby karinha » Fri Jun 02, 2017 12:55 pm

Code: Select all  Expand view  RUN

/*
** autor: JOSÉ MARIA DA SILVA (JMSILVA)

** xHarbour 1.2.1 com FIVEWIN

** DATA: 29/12/2011

** CIDADE: CARAGUATATUBA/SP

** OBS: PRECISA TER BROFFICE INSTALADO

*/


#INCLUDE "FIVEWIN.CH"

#include "FGet.ch"

Function Main ()

   Local oService, oDesktop, oDocument, oTexto

   Local oDlg, oGet, cVarTxt, cFile, aProp:={}

   cFile := cGetFile( "Arquivo (doc,odt)|*.doc;*.odt|",;
                      "Selecione o Arquivo (Doc/Odt)", 4 )

   IF EMPTY(cFILE) ; RETURN nil ; ENDIF

      cFile := "file:///"+StrTran(cFile,"\","/")

   TRY

      oService := TOleAuto():New("
com.sun.star.ServiceManager")

   CATCH

      MSGSTOP("
Desculpe, precisa ter o BrOffice instalado.","Alerta")

      RETURN NIL

   END

   oDesktop := oService:createInstance("
com.sun.star.frame.Desktop")

   AAdd(aProp,MakePropertyValue(oService,"
Hidden",.T.)) //seta prop para ocultar

   oDocument := oDesktop:loadComponentFromURL(cFile, "
_blank", 0, aProp) // {}) //abre o doc

   //OBTÉM O TEXTO

   oTexto = oDocument:getText()

   cVarTxt := oTexto:getString()

   oDocument:Close(.T.) //fechao doumento

   DEFINE DIALOG oDlg TITLE "
Visualiza documentos doc/odt" size 640,480

   @ 0.5, 01 FORMAT GET oGet VAR cVarTXT OF oDlg SIZE 310,220 UPDATE

   ACTIVATE DIALOG oDlg CENTERED

Return Nil

**==============================================================================

STATIC FUNCTION MakePropertyValue(oService,cName,nValue)

**==============================================================================

   LOCAL oStruct := oService:Bridge_GetStruct("
com.sun.star.beans.PropertyValue")

   oStruct:Name := cName

   oStruct:Value := nValue

RETURN(oStruct)
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7855
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Very strange OLE-problem

Postby karinha » Fri Jun 02, 2017 12:59 pm

Code: Select all  Expand view  RUN

#Include "Fivewin.ch"

**==============================================================================

Function Main()

**==============================================================================

   LOCAL cFile := CurDrive()+":\"+CurDir()+"\teste.doc"

   LOCAL oWord, oDocument, oText, cText

   TRY

      oWord := CreateObject( "
Word.Application" )

   CATCH

      MsgStop("
ERRO! Word não instalado.","Alerta")

      RETURN Nil

   END

   oDocument := oWord:documents:open(cFile) //abre um arquivo doc/rtf

   // get -> seleciona o objeto

   oText := oWord:selection()

   // oculta o word

   oWord:visible := .F.

   cText := oText:Text

   oDocument:close() //fecha o doc

   oWord:quit() //finaliza

   MsgInfo(cText)

Return Nil
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7855
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Very strange OLE-problem

Postby karinha » Fri Jun 02, 2017 1:12 pm

Code: Select all  Expand view  RUN

*
*  HBTEST.PRG
*
*  Este ejemplo es para probar con Harbour en modo consola, sin FiveWin
*  para Harbour.
*
*  This example is done for testing with Harbour in console mode, without
*  FiveWin for Harbour.
*


#define CRLF Chr( 13 ) + Chr( 10 )


PROCEDURE MAIN()

   LOCAL nOption

   CLS
   SetColor("W+/R")
   @  6, 25 TO 16, 55 DOUBLE
   @  8, 28 SAY "Test hbole.lib with ..."

   While .t.
      @ 10, 32 PROMPT "Excel"
      @ 11, 32 PROMPT "Word"
      @ 12, 32 PROMPT "Internet Explorer"
      @ 13, 32 PROMPT "Outlook"
      @ 14, 32 PROMPT "Quit"

      MENU TO nOption

      IF nOption == 0
         nOption := 5
      ELSEIF nOption == 1
         EXCEL97()
      ELSEIF nOption == 2
         WORD97()
      ELSEIF nOption == 3
         IEXPLORER()
      ELSEIF nOption == 4
         OUTLOOK()
      ELSEIF nOption == 5
         EXIT
      ENDIF
   End

   SetColor("W/N")
   CLS

RETURN

//--------------------------------------------------------------------

STATIC PROCEDURE EXCEL97()

   LOCAL oExcel, oHoja

   oExcel := TOleAuto():New( "Excel.Application" )

   oExcel:WorkBooks:Add()

   oHoja := oExcel:ActiveSheet()

   oHoja:Cells:Font:Name := "Arial"
   oHoja:Cells:Font:Size := 12

   oHoja:Cells( 3, 1 ):Value := "Text:"
   oHoja:Cells( 3, 2 ):Value := "This is sample text"
   oHoja:Cells( 4, 1 ):Value := "Numeric:"
   oHoja:Cells( 4, 2 ):NumberFormat := "#.##0,00"
   oHoja:Cells( 4, 2 ):Value := 1234.50
   oHoja:Cells( 5, 1 ):Value := "Logical:"
   oHoja:Cells( 5, 2 ):Value := .T.
   oHoja:Cells( 6, 1 ):Value := "Date:"
   oHoja:Cells( 6, 2 ):Value := DATE()

   oHoja:Columns( 1 ):Font:Bold := .T.
   oHoja:Columns( 2 ):HorizontalAlignment := -4152  // xlRight

   oHoja:Columns( 1 ):AutoFit()
   oHoja:Columns( 2 ):AutoFit()

   oHoja:Cells( 1, 1 ):Value := "OLE in Harbour"
   oHoja:Cells( 1, 1 ):Font:Size := 16
   oHoja:Range( "A1:B1" ):HorizontalAlignment := 7

   oHoja:Cells( 1, 1 ):Select()
   oExcel:Visible := .T.

   oHoja:End()
   oExcel:End()

RETURN

//--------------------------------------------------------------------

STATIC PROCEDURE WORD97()

   LOCAL oWord, oTexto

   oWord:=TOleAuto():New( "Word.Application" )

   oWord:Documents:Add()

   oTexto := oWord:Selection()

   oTexto:Text := "Harbour hbOLE.lib"+CRLF+"Word Sample"+CRLF
   oTexto:Font:Name := "Arial"
   oTexto:Font:Size := 48
   oTexto:Font:Bold := .T.

   oWord:Visible := .T.
   oWord:WindowState := 1  // Maximize

   oTexto:End()
   oWord:End()

RETURN

//--------------------------------------------------------------------

STATIC PROCEDURE IEXPLORER()

   LOCAL oIE

   oIE:=TOleAuto():New( "InternetExplorer.Application" )

   oIE:Visible := .T.

   oIE:Navigate( "http://www.harbour-project.org" )

   oIE:End()

RETURN

//--------------------------------------------------------------------

STATIC PROCEDURE OUTLOOK()

   LOCAL oOL, oLista, oMail, i

   oOL := TOleAuto():New( "Outlook.Application.9" )

   IF Ole2TxtError() != "S_OK"

      Alert("Outlook is not available", "Error")

   ELSE

      oMail := oOL:CreateItem( 0 )  // olMailItem

      FOR i := 1 TO 10
         oMail:Recipients:Add( "Contact" + LTRIM( STR( i, 2 ) ) + ;
               "<contact" + LTRIM( STR( i, 2 ) ) + "@server.com>" )
      NEXT

      oLista := oOL:CreateItem( 7 )  // olDistributionListItem
      oLista:DLName := "Test with distribution list"
      oLista:Display( .F. )
      oLista:AddMembers( oMail:Recipients )
      oLista:Save()
      oLista:Close( 0 )

      oMail:End()
      oLista:End()
      oOL:End()

   ENDIF

RETURN
 
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7855
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Very strange OLE-problem

Postby hmpaquito » Fri Jun 02, 2017 1:34 pm

hmpaquito
 
Posts: 1482
Joined: Thu Oct 30, 2008 2:37 pm

Re: Very strange OLE-problem

Postby Enrico Maria Giordano » Fri Jun 02, 2017 5:32 pm

driessen wrote:Hello,

I use this code :
Code: Select all  Expand view  RUN
PRIVATE CuWole1,CuDoc1

CuWole1 := TOleAuto():New("Word.Application") ; ENDIF
CuDoc1  := CuWole1:Documents:Open(TRIM(US->DRIVE_BWP) + cBest)
MsgInfo(CuDoc1)
In Windows 7, the msginfo returns "Object", as it should be.
In Windows 10 though, the msginfo returns "Array". This results in other errors while saving etc.

Anyone any idea why there is a difference?

Thanks.


Can we see a compilable and runnable sample showing the problem, please?

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8719
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Very strange OLE-problem

Postby anserkk » Sat Jun 03, 2017 4:05 am

driessen wrote:Hello,

I use this code :
Code: Select all  Expand view  RUN
PRIVATE CuWole1,CuDoc1

CuWole1 := TOleAuto():New("Word.Application") ; ENDIF
CuDoc1  := CuWole1:Documents:Open(TRIM(US->DRIVE_BWP) + cBest)
MsgInfo(CuDoc1)
In Windows 7, the msginfo returns "Object", as it should be.
In Windows 10 though, the msginfo returns "Array". This results in other errors while saving etc.

Anyone any idea why there is a difference?

Thanks.


Does TRIM(US->DRIVE_BWP) + cBest returns the full path of your Word document file ?
User avatar
anserkk
 
Posts: 1333
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: dtussman and 38 guests