Simple RSS reader for your applications...

Postby Andrés González » Wed Aug 27, 2008 1:05 pm

They must be and explanation about where my error come from, in the winole32.prg from xharbour there is no message like:
Destructors disabled! Destructor of class "TOLEAUTO' can't be executed. May be you are right, but if I don't destroy the objects created I always advised with the message "Destructors disabled! Destructor of class "TOLEAUTO' can't be executed." even if the xharbour is the lasted. I'll try to prepare a zip sample to show the error. Thanks.
Saludos

Andrés González desde Mallorca
User avatar
Andrés González
 
Posts: 628
Joined: Thu Jan 19, 2006 10:45 am
Location: Mallorca

Postby Andrés González » Wed Aug 27, 2008 1:21 pm

Please NageswaraRao, G. try:

Must openoffice be instaled; open a new document and go to exit, even if you exit openoffice:writer or not. After try to uncomment ::oService:=nil in method finaliza().

main.prg
Code: Select all  Expand view
#include "FiveWin.ch"

static oWnd

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

function Main()

   DEFINE WINDOW oWnd FROM 1, 1 TO 22, 75 ;
      TITLE "Ejemplos de OpenOffice" ;
      MENU  BuildMenu()

   SET MESSAGE OF oWnd ;
      TO FWVERSION + " " + FWCOPYRIGHT ;
      CENTERED DATE CLOCK KEYBOARD 2007

   ACTIVATE WINDOW oWnd MAXIMIZED     // Now the app will start maximized

return nil

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

function BuildMenu()

   local oMenu

   MENU oMenu 2007
      MENUITEM "Writer"
      MENU
         MENUITEM  "Abrir un archivo en &blanco..." ;
            ACTION  Writer00() ;
            MESSAGE "Solamente abre un fichero en blanco"
         MENUITEM  "Abrir un archivo un archivo determinado..." ;
            ACTION  Writer01() ;
            MESSAGE "Solamente abre un fichero"
      ENDMENU



      MENUITEM "&Exit"
      MENU
         MENUITEM "&Calculator..." ;
            ACTION WinExec( "Calc" ) ;
            MESSAGE "Using the Windows calculator"

      SEPARATOR
         MENUITEM "&End..."  ;
            ACTION If( MsgYesNo( "Quieres salir ?", "Porfavor, selecciona" ),;
                      (TOpenOffice():Finaliza(), oWnd:End()),) ;
            MESSAGE "Salir de la aplicación"
      ENDMENU
   ENDMENU

return oMenu

/*-----------------------------------------------------------------------------------------------*/
FUNCTION Writer00()
   LOCAL oDoc
   /* Para abrir un documento en blanco basta que no mandemos nada a la clase tOpenOffic:Writter */
   MsgRun( "Instanciando OpenOffice",;
           "Un momento por favor..."   ,;
           { || oDoc := TOpenOffice():Writer( , .T. ) } )
           
   RETURN NIL


FUNCTION Writer01()
   LOCAL cFile, oDoc
   cFile := cGetFile32( "*.*", "Buscar Archivos" )
   IF cFile = NIL; RETURN NIL; ENDIF

   //cFilePath( GetModuleFileName( GetInstance() ) ) + "Macros.odt"
   MsgRun( "Instanciando OpenOffice",;
           "Un momento por favor..."   ,;
           { || oDoc := TOpenOffice():Writer( cFile , .T. ) } )        //cFile
           
           

   RETURN NIL





And the class tha I'm creating:
Code: Select all  Expand view

#include "Fivewin.ch"

#DEFINE CR CHR(13)
#DEFINE wdTAB CHR(9)
** API CONTROL CHARACTERS FOR insertControlCharacter
#define PARAGRAPH_BREAK   0
#define LINE_BREAK        1
#DEFINE HARD_HYPHEN       2
#DEFINE SOFT_HYPHEN       3
#DEFINE HARD_SPACE        4
#DEFINE APPEND_PARAGRAPH  5
#DEFINE STANDARD_FORMAT   ".odt"
/*-----------------------------------------------------------------------------------------------*/

CLASS TOpenOffice
   CLASSDATA oService         // Objeto Servicio
   CLASSDATA oDesktop         // Objeto Escritorio
   CLASSDATA oDisp            // Objeto Disp
   DATA oDoc                  // Objeto Documento
    * DATA oTxt                // Objeto Texto
   DATA oRng                  // Objeto Rango
   DATA oCursor               // Objeto Cursor
   DATA oSourceframe          // Objeto SourceFrame
   DATA lOpen   Init .T.      // Boleano para saber si esta abierto un objeto
   METHOD Writer(cFile)
   METHOD Close()             INLINE ::oDoc:Close( .T. )
   METHOD Copy()              INLINE ::Dispatch( "Copy" )
   METHOD ConvertToURL( cFile )
   METHOD Dispatch( cMethod, aArgs )
   METHOD GetPropertyValue( cName, cValue )
   METHOD New() Constructor
   METHOD Print()             INLINE ::Dispatch( "Print" )
   METHOD PrintDefault()      INLINE ::Dispatch( "PrintDefault" )
   METHOD Visible( lVisible )
   METHOD Paste()             INLINE ::Dispatch( "Paste" )
   METHOD Preview()           INLINE ::Dispatch( "PrintPreview" )
   METHOD Finaliza()
   ERROR HANDLER ERROR( xVal )
ENDCLASS

/*-----------------------------------------------------------------------------------------------*/
METHOD Visible( lVisible )
   IF lVisible == NIL
      RETURN ::oDoc:getCurrentController():GetFrame():getComponentWindow():IsVisible()
   ELSE
      ::oDoc:getCurrentController():GetFrame():getComponentWindow():setVisible( lVisible )
   ENDIF
   RETURN NIL


/*-----------------------------------------------------------------------------------------------*/
METHOD Writer( cFile, lVisible ) CLASS TOpenOffice

   LOCAL cUrl, oDoc, oTxt, aArg := {}
   ::New()
   IF !::lOpen; RETURN NIL; ENDIF
   DEFAULT lVisible := .T.
   IF cFile == NIL
      cUrl  := "private:factory/swriter"
   ELSE
      cUrl  := "file:///" + cFile
   ENDIF

   IF !lVisible
      AAdd( aArg, ::GetPropertyValue( "Hidden", .T. ) )   //Le asigna la propiedad de que este escondido
                                                          //(Ojo no puedes  volverlo a mostrar) para
                                                          //ejecutarse mas rapido. Ejemplo: realizar una
   ENDIF                                                  //impresion de un documento sin que lo puedan modificar

   oDoc := ::oDesktop:LoadComponentFromUrl( cUrl, "_blank", 0, aArg )

   RETURN oDoc //oSheet



/*-----------------------------------------------------------------------------------------------*/
METHOD Dispatch( cMethod, aArgs ) CLASS TOpenOffice
   DEFAULT aArgs := {}
   IF ValType( aArgs ) == "O"; aArgs := { aArgs }; ENDIF
   ::oDisp:ExecuteDispatch( ::oDoc:GetCurrentController():GetFrame(), ".uno:" + cMethod, "", 0, aArgs )
   RETURN NIL

/*-----------------------------------------------------------------------------------------------*/
METHOD GetPropertyValue( cName, xValue ) CLASS TOpenOffice
   LOCAL oArg
   oArg := ::oService:Bridge_GetStruct( "com.sun.star.beans.PropertyValue" )
   oArg:Name  := cName
   oArg:Value := xValue
   RETURN oArg

/*-----------------------------------------------------------------------------------------------*/
METHOD New() CLASS TOpenOffice
   // Par usar cualquier aplicativo de OpenOffice lo primero que se tiene que hacer es cargar el ServiceManager
   // una vez se tiene capturado se debe instanciar el objeto Destop y finlamente el Despachador

   IF ::oDesktop != NIL; RETURN SELF; ENDIF
   IF ::oService != NIL; RETURN SELF; ENDIF

   ::lOpen := .T.
   TRY
      ::oService := TOleAuto():New( "com.sun.star.ServiceManager" )
   CATCH
      MsgStop( "No se puede iniciar el servicio manager" )
      ::lOpen := .F.
   END

   IF ::lOpen
      ::oDesktop := ::oService:CreateInstance( "com.sun.star.frame.Desktop" )
      ::oDisp    := ::oService:CreateInstance( "com.sun.star.frame.DispatchHelper" )
   ENDIF
   RETURN  SELF

/*-----------------------------------------------------------------------------------------------*/
METHOD ERROR( xVal ) CLASS TOpenOffice
   MsgInfo( __GetMessage() + " Inexistente" )
   RETURN NIL

/*-----------------------------------------------------------------------------------------------*/
METHOD ConvertToURL( cFile ) CLASS TOpenOffice
   LOCAL nFor, nLen := Len( cFile )
   FOR nFor := 1 TO nLen
      IF cFile[ nFor ] == "\"
         cFile[ nFor ] := "/"
      ENDIF
   NEXT
   RETURN cFile

   /*-----------------------------------------------------------------------------------------------*/
METHOD Finaliza() CLASS TOpenOffice
    ::oDesktop:=nil
      ::oDoc:=nil
      ::oDisp:=nil
      *::oService:=nil      //Try to uncomment  (created with toleauto)

Return nil
Saludos

Andrés González desde Mallorca
User avatar
Andrés González
 
Posts: 628
Joined: Thu Jan 19, 2006 10:45 am
Location: Mallorca

Postby nageswaragunupudi » Wed Aug 27, 2008 1:50 pm

Nice Work.

I do not have Open Office. I shall test your code and also learn from it, after I download and install Open Office.

But the ole objects I create for excel, word, RDMS and any others are working fine.

By the way I like to mention here that when I tried to keep Ole Objects in CLASSDATA, I did face problems. Some months back. Then I moved them to statics and it wsa okay. I do not remember what was the problem I faced at that time. I did not try it again later. I dont know if this information helps you.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10627
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Postby Andrés González » Wed Aug 27, 2008 10:18 pm

Thanks, that was the first question that I did to my friend Biel: What difference are between CLASSDATA and DATA, may be that's the problem because it can't be destroyed automatically by tOleAuto, always I destroy it with object:=nil and work fine.

Thanks a lot.
Saludos

Andrés González desde Mallorca
User avatar
Andrés González
 
Posts: 628
Joined: Thu Jan 19, 2006 10:45 am
Location: Mallorca

Postby Andrés González » Wed Aug 27, 2008 10:35 pm

Please Enrico, could you test my example if destroy all objects automatically.

Thanks.
Saludos

Andrés González desde Mallorca
User avatar
Andrés González
 
Posts: 628
Joined: Thu Jan 19, 2006 10:45 am
Location: Mallorca

Postby Antonio Linares » Wed Aug 27, 2008 10:36 pm

Andrés,

> What difference are between CLASSDATA and DATA

CLASSDATA are properties _shared_ by all objects that belong to a Class.
i.e.: CLASSDATA lRegistered AS LOGICAL is a logical value (only one shared item!) used by all objects of that Class.

A DATA is a property that just belongs to an object. Each object may have a different value for its DATA.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42082
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Enrico Maria Giordano » Wed Aug 27, 2008 10:39 pm

Andrés González wrote:Please Enrico, could you test my example if destroy all objects automatically.

Thanks.


No sorry, as I haven't OpenOffice installed.

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

Postby Andrés González » Thu Aug 28, 2008 7:44 am

Antonio, do you think that I'm doing something wrong putting the object ServerManager as a CLASSDATA. It's a module shared by all the program from openoffice (Writer, Calc, draw...). Antonio could you check the program and tell me why if Enrico say that all the objects will be destroyed automatically, in this case isn't true, and where de message come from.

Thanks.
Saludos

Andrés González desde Mallorca
User avatar
Andrés González
 
Posts: 628
Joined: Thu Jan 19, 2006 10:45 am
Location: Mallorca

Postby Enrico Maria Giordano » Thu Aug 28, 2008 8:20 am

This is a reduced sample of the problem:

Code: Select all  Expand view
FUNCTION MAIN()

    LOCAL oTest := TTest()

    oTest:oRs = CREATEOBJECT( "ADODB.Recordset" )

    RETURN NIL


#include "Hbclass.ch"


CLASS TTest

    CLASSDATA oRs

ENDCLASS


I'm going to ask for info to the xHarbour developers and report back here...

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

Postby James Bott » Thu Aug 28, 2008 3:18 pm

It would seem to me that CLASSDATA is like a public, so it never goes out of scope. This would prevent automatic destruction of the object.

Andrés, the simple test is to change it to just DATA then try the program and see if the error goes away.

Regards,
James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby jose_murugosa » Thu Aug 28, 2008 4:17 pm

Andrés González wrote:Rochiha, the program run ok and look marvellous, but why i have to comment this lines to run de program, where are they defined. See "*"

Code: Select all  Expand view
    oFRLbx:nStyle        := 1
     oFRLbx:nLineStyle    := 10
     *oFRLbx:nHeaderStyle  := 2
     *oFRLbx:nHeaderHeight := 20
     *oFRLbx:nLineHeight   := 15
     oFRLbx:lMChange      := .f.
     *oFRLbx:lOnlyBorder   := .f.
     *oFRLbx:lAdjLastCol   := .f.
     *oFRLbx:Set3DStyle()
     // -> Cabecalho
     oFRLbx:nClrBackHead  := nRGB(194,218,242)
     // -> Linha divisora
     *oFRLbx:nClrLine      := nRGB(194,218,242)
     // -> Cores das linhas Texto e Fundo
     // -> Cor do cursor com foco
     oFRLbx:nClrForeFocus := CLR_BLACK
     oFRLbx:nClrBackFocus := nRGB(194,218,242)
     // -> Cor do cursor sem foco
     *oFRLbx:nClrNFFore    := CLR_BLACK
     *oFRLbx:nClrNFBack    := nRGB(194,218,242)
     oFRLbx:SetFont( oFntLBX )


Rochina is using wbrowse of Hernán, This variables does not exist in fwh native wbrowse
Saludos/Regards,
José Murugosa
"Los errores en programación, siempre están entre la silla y el teclado y la IA!!"
User avatar
jose_murugosa
 
Posts: 1180
Joined: Mon Feb 06, 2006 4:28 pm
Location: Uruguay

Postby Enrico Maria Giordano » Fri Aug 29, 2008 8:29 am

Enrico Maria Giordano wrote:This is a reduced sample of the problem:

Code: Select all  Expand view
FUNCTION MAIN()

    LOCAL oTest := TTest()

    oTest:oRs = CREATEOBJECT( "ADODB.Recordset" )

    RETURN NIL


#include "Hbclass.ch"


CLASS TTest

    CLASSDATA oRs

ENDCLASS


I'm going to ask for info to the xHarbour developers and report back here...

EMG


Fixed:

2008-08-28 22:30 UTC-0430 Ron Pinkas <ron/at/xharbour.com>
* include/classes.h
* source/vm/classes.c
+ Added hb_clsClearAllClassDatas()
* source/vm/hvm.c
+ Add call to clear class datas before disabling Destructors
/*
This change dismisses the restriction on storing a destructable object
into a classdata, but by the time such Destructor are activated
classdatas might have been cleaned, which means that Destructors should
not rely on any classdata value.
*/


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

Postby Antonio Linares » Fri Aug 29, 2008 8:53 am

Enrico,

Thanks! :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42082
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Andrés González » Fri Aug 29, 2008 3:23 pm

Thanks Enrico, I'll upgrade and test now.
Saludos

Andrés González desde Mallorca
User avatar
Andrés González
 
Posts: 628
Joined: Thu Jan 19, 2006 10:45 am
Location: Mallorca

Postby Andrés González » Fri Aug 29, 2008 3:25 pm

Thanks Jose Mugurusa.
Saludos

Andrés González desde Mallorca
User avatar
Andrés González
 
Posts: 628
Joined: Thu Jan 19, 2006 10:45 am
Location: Mallorca

PreviousNext

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 99 guests