Variant SetObject: how to free the object?

Discussions specific to Team Developer 5.1.

Variant SetObject: how to free the object?

Postby yg@msgtech.de » Tue Jun 23, 2009 11:33 pm

Hi,

we use ActiveX to communicate with MS Office, e.g. Excel. For some functions as Goto is it necessary to pass an object as a parameter in a variant. For example:

vREFERENCE.SetObject (objRANGE)

But when I have this line in my program, I can't finish Excel completely. All Detaches, Quit and Releases do not really work: The Excel application is closed, but it remains as a process in the task manager, and it is not possible to start Excel again until the process is killed. Also the end of the program doesn't change the situation. Also some statement like
vREFERENCE.SetNumber (0, VT_I4)
or
vREFERENCE.SetObject (objDUMMY)
doesn't help.

The problem occurs only with TD 5.1 SP6, with TD 2.1 we had no problem.

Obviously the object is copied into the heap und the Excel process doesn't finish until it is destroyed. But how to destroy or free it?

The complete code of a small example program is:

Set bOK = objAPPLICATION.Create ()
!
Set bOK = objAPPLICATION.PropSetVisible (TRUE)
!
Set bOK = objAPPLICATION.PropGetWorkbooks (objWORKBOOKS)
!
Call vOPTIONAL.MakeOptional ()
Set bOK = objWORKBOOKS.Add (vOPTIONAL,
objWORKBOOK)
!
Set bOK = objWORKBOOK.PropGetActiveSheet (objSHEET)
!
Set bOK = vCELL1.SetString ('A1')
!
Set bOK = objSHEET.PropGetRange (vCELL1,
vCELL1,
objRANGE)
!
Call vREFERENCE.SetObject (objRANGE)
!
Call objRANGE.Detach ()
!
Call objSHEET.Release ()
!
Call vFALSE.SetBoolean (FALSE)
!
Call objWORKBOOK.Close (vFALSE,
vFALSE,
vFALSE)
Call objWORKBOOK.Detach ()
!
Call objWORKBOOKS.Detach ()
!
Call objAPPLICATION.Quit ()
!
Call objAPPLICATION.Release ()


Without the line

Call vREFERENCE.SetObject (objRANGE)

Excel finishs completely, but with this line it doesn't.


Thank you for your help

Yvonne
yg@msgtech.de
 
Posts: 52
Joined: Thu Jan 22, 2009 3:38 am

Re: Variant SetObject: how to free the object?

Postby Kitchman » Tue Dec 15, 2009 6:29 am

I have exactly the same problem. Nobody has a solution ?

Kitchman
Kitchman
 
Posts: 9
Joined: Fri Feb 15, 2008 6:32 am
Location: France

Re: Variant SetObject: how to free the object?

Postby Kitchman » Tue Dec 15, 2009 9:09 am

I found a solution ! :D

In Automation.apl, change the method SetObject from class Variant like this :

Function: SetObject
Description:
Returns
Boolean:
Parameters
Object: o
Static Variables
Local Variables
Object: objDummy = OBJ_Null
Boolean: returnValue

Actions
Set returnValue = __SetObject(o)
Set o = objDummy
Return returnValue


In bold, the new code...

It works ! :wink:
Kitchman
 
Posts: 9
Joined: Fri Feb 15, 2008 6:32 am
Location: France

Re: Variant SetObject: how to free the object?

Postby bills » Tue Dec 15, 2009 10:21 am

In TD objects are always passed by reference. When you adding OBJNull to the argument o you are setting to null also the reference in the calling function. The app will crash if you call any method on the argument object.
bills
 

Re: Variant SetObject: how to free the object?

Postby Kitchman » Tue Dec 15, 2009 10:38 am

bills wrote:In TD objects are always passed by reference. When you adding OBJNull to the argument o you are setting to null also the reference in the calling function. The app will crash if you call any method on the argument object.


It works perfectly for me ! :wink:

But, I must copy the variable (ie sheetTemp in my case) before call SetObjet to save the value of the variable...

I didn't use any method of the objects, I use it to give to the ActiveX Excel...

Sorry for my english, I'm french... :wink:
Kitchman
 
Posts: 9
Joined: Fri Feb 15, 2008 6:32 am
Location: France

Re: Variant SetObject: how to free the object?

Postby mkonir » Tue Jan 04, 2011 8:01 am

Bills is correct, once you send the Variant to some functions application will crash.
We ran into this problem when using the Copy funciton of Excel_WorkSheet

Code: Select all
Function: Copy
   Description:
   Returns
      Boolean:
   Parameters
      FunctionalVar: Before
         Class: Variant
      FunctionalVar: After
         Class: Variant
   Static Variables
   Local variables
      Boolean: tmpret
   Actions
      Call __ObjectPushVariant(Before)
      Call __ObjectPushVariant(After)
      Set tmpret = __ObjectInvoke("Copy", INVOKE_FUNCTION)
      Call __ObjectFlushArgs()
      Return tmpret

and did the following workaround -- we're pushing the object directly, not through variant:

Code: Select all
Function: Copy
   Description:
   Returns
      Boolean:
   Parameters
      FunctionalVar: Before
         Class: Object
      FunctionalVar: After
         Class: Object
   Static Variables
   Local variables
      Boolean: tmpret
      FunctionalVar: varOptional
         Class: Variant
   Actions
      Call varOptional.MakeOptional ()
      If Before != OBJ_Null
         Call __ObjectPushObjectByRef (Before)
      Else
         Call __ObjectPushVariant (varOptional)
      If After != OBJ_Null
         Call __ObjectPushObjectByRef (After)
      Else
         Call __ObjectPushVariant (varOptional)
      Set tmpret = __ObjectInvoke("Copy", INVOKE_FUNCTION)
      Call __ObjectFlushArgs()
      Return tmpret

It would be nice if Unify addressed this issue.
User avatar
mkonir
 
Posts: 215
Joined: Tue Oct 23, 2007 6:47 am
Location: Prague, Czech Republic


Return to Team Developer 5.1

Who is online

Users browsing this forum: No registered users and 2 guests

cron