Simple RSS reader for your applications...

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

Post by Andrés González »

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: 625
Joined: Thu Jan 19, 2006 10:45 am
Location: Mallorca

Post by Andrés González »

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

#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


#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
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Post by nageswaragunupudi »

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
Andrés González
Posts: 625
Joined: Thu Jan 19, 2006 10:45 am
Location: Mallorca

Post by Andrés González »

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: 625
Joined: Thu Jan 19, 2006 10:45 am
Location: Mallorca

Post by Andrés González »

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

Thanks.
Saludos

Andrés González desde Mallorca
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

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
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

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
Andrés González
Posts: 625
Joined: Thu Jan 19, 2006 10:45 am
Location: Mallorca

Post by Andrés González »

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
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

This is a reduced sample of the problem:

Code: Select all

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
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post by James Bott »

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
jose_murugosa
Posts: 943
Joined: Mon Feb 06, 2006 4:28 pm
Location: Uruguay
Contact:

Post by jose_murugosa »

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

    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
FWH + Harbour + Bcc7. Una seda!
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

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

Code: Select all

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
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Enrico,

Thanks! :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Andrés González
Posts: 625
Joined: Thu Jan 19, 2006 10:45 am
Location: Mallorca

Post by Andrés González »

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

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

Post by Andrés González »

Thanks Jose Mugurusa.
Saludos

Andrés González desde Mallorca
Post Reply