Theos PowerBasic Museum 2017

Archive => Discussion - Legacy Software (PBWIN 9.0+/PBCC 5.0+) => Topic started by: Gil Ben-Zvi on November 16, 2009, 05:39:11 PM

Title: Problem using direct method
Post by: Gil Ben-Zvi on November 16, 2009, 05:39:11 PM
Any idea why the following code crashes?

MSWord 2007 Interface defintions file ("Office12.inc") generated using PBrow.


Sub Speller(UWord As String)
 
  Local oWordApp        As Int__Application      ' Application Interface.
  Local oWordDoc        As Int__Document         ' Document Interface.
  Local oSuggestions    As SpellingSuggestions   ' Spelling Suggestions collection object.
  Local NumWords        As Long

  ' Open a new instance of MSWORD
  oWordApp = NewCom $PROGID_Word_Application
  If IsTrue IsObject(oWordApp) Then
     ' Must have at least one document.
     If oWordApp.Documents.Count = 0 Then
        oWordDoc = oWordApp.Documents.Add
     End If
     oSuggestions = oWordApp.GetSpellingSuggestions(UWord)
     If IsObject(oSuggestions) Then
        ' CRASH ON NEXT STATEMENT.
        NumWords = oSuggestions.Count
        If oSuggestions.SpellingErrorType <> %WdSpellingErrorType_wdSpellingCorrect Then
           
        End If
       
     End If
  End If

End Sub


Gil.
Title: Re: Problem using direct method
Post by: Paul Squires on November 16, 2009, 06:49:55 PM
I may be 100% wrong, but I thought that I remembered Jose mentioning that all of the Office applications (Word, Excel, etc...) operate using a Dispatch interface instead of a direct interface.
Title: Re: Problem using direct method
Post by: Paul Squires on November 16, 2009, 06:51:33 PM
Actually, Jose kind of alludes to this in his comments about Excel in another post from today: http://www.jose.it-berater.org/smfforum/index.php?topic=3364.0
Title: Re: Problem using direct method
Post by: José Roca on November 16, 2009, 07:13:36 PM
 
And not only that. If you want to be safe, use late binding because M$ has broken all his COM rules with these applications and, if you use early binding, an application compiled using an include file for one version may crash when used with a different version.

The object model of the Office applications has been designed to work mainly with VBA.