Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to remove this object ?

Status
Not open for further replies.

Johnweida

MIS
Apr 29, 2003
91
CN
experts,

***** in form's INI method
public olword
olword = createobject("word.application")
*******************

***** in unload method
thisform.removeobject("olword")
Error message "unkown member olword"
**********************

help me please.

John Satellite
 
You create olWord as a public variable, not a property of the form. That's why Thisform.Removeobject doesn't work on it. Instead, you should do:
Code:
olWord.Quit()
release olWord



-BP
 
John,

Barbara has given you the correct answer. However, I would add that it would have been better to use a form property in this case rather than a public variable. Public variables should be used sparingly, and only when a global scope is required. If you want to store some information that is scoped to a form, make it a form property.

To do so, add the property (say, oWord) to the form in the form designer. Then, in the Init, do this:
THISFORM.oWord = CREATEOBJECT("word.application")

In the Unload:
THISFORM.oWord.Quit
THISFORM.oWord = NULL

(Actually, that last line is not really necessary, as the form is closing anyway, but I like to do it for tidiness.)

Mike


Mike Lewis
Edinburgh, Scotland
 
Experts,

Thanks a lot for your kindly help.
But there are still some troubles when I start and quit Word. I need your help.

***** in the init
public olword
olword = createobject("word.application")
*** or THISFORM.oWord = CREATEOBJECT("word.application")

***** in the unload
olWord.Quit()
release olWord
*** or THISFORM.oWord.Quit
***THISFORM.oWord = NULL

1) The error message appears as "The RPC Server is unavailable" when I click the cross("X") button on the right-up corner to quit Word first,then close the form.

2) Word is started but has no focus.

John Satellite
 

1) The message will always come if you close Word manually. VFP still holding the object interface but the object itself no longer exist. In that case you must trapped the error.

for example:
lError = .F.
On error lError = .T.
olWord.Quit
On error
If lError
*** Error, do something
endif


2) in the init event try to add this:

olWord.Visible = .T.
** or Thisform.oWord.Visible = .T.



-- AirCon --
 
John,

Basically, you have to choose between making Word visible, in which case it is always possible that the user can close it manually, or keeping it invisible and closing it in your code (by calling the .Quit() method).

If you need the user to interact with Word, it is probably better to let them close it themselves.

Mike


Mike Lewis
Edinburgh, Scotland
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top