Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. ActiveXのComponentOnFailureプロパティを設定します。
  2. コードでエラーをトラップします。
  3. ActiveXのComponentOnFailureプロパティを「SignalError」に設定します。

...

  1. Image Added


*Trap error in code
Function Options(*DIRECT)
Begin_Com Role(*EXTENDS #PRIM_FORM) Clientheight(376) Clientwidth(208) Height(414) Left(295) Top(178) Width(224)
 
Define_Com Class(#PRIM_PHBN) Name(#StartWord) Caption('Start Word') Displayposition(1) Left(8) Parent(#COM_OWNER) Tabposition(1) Top(8) Width(193)
 
Define_Com Class(#PRIM_PHBN) Name(#CreateDocument) Caption('Create Document') Displayposition(2) Left(8) Parent(#COM_OWNER) Tabposition(2) Top(40) Width(193)
 
Define_Com Class(#PRIM_PHBN) Name(#FindBookmark) Caption('Access Bookmark') Displayposition(3) Left(8) Parent(#COM_OWNER) Tabposition(3) Top(72) Width(193)
 
Define_Com Class(#va_word.Application) Name(#Word) Reference(*dynamic)
Define_Com Class(#va_word.Document) Name(#ActiveDocument) Reference(*dynamic)
Define_Com Class(#va_word.Bookmarks) Name(#Bookmarks) Reference(*dynamic)
 
Evtroutine Handling(#StartWord.Click)

* Start Start an instance of word
Set_Ref Com(#Word) To(*Create_as #va_word)
 
Endroutine
 
Evtroutine Handling(#CreateDocument.Click)
 
If (#Word *IsNot *null)
 
If (#ActiveDocument *Is *null)

* Open a new document
#ActiveDocument <= #Word.Documents.Add

* Get the reference to the Bookmarks of the Active Document
* This is necessary to be able to listen to the activeX errors

#Bookmarks <= #ActiveDocument.Bookmarks
 
Else
 
Use Builtin(ov_message_box) With_Args("Document Aleady Exists")
 
Endif
 
Else
 
Use Builtin(ov_message_box) With_Args("Word Has Not Yet been Started")
 
Endif
 
Endroutine
 
Evtroutine Handling(#FindBookmark.Click)
 
Define_Com Class(#va_word.Bookmark) Name(#Bookmark) Reference(*dynamic)

* Ensure there is an Active Document
If (#ActiveDocument *IsNot *null)

* Try to access a bookmark
* As this is a new document there will be no bookmarks

* This will generate an ActiveX error on Bookmarks ONLY
 
#Bookmark <= #Bookmarks<1>
 
Else
 
Use Builtin(Ov_message_box) With_Args("There Is No Active Document")
 
Endif
 
Endroutine
 
Evtroutine Handling(#Word.ComponentError)

* This routine will never fire.  The   The bookmark error is specific to the Bookmark instance
 
Use Builtin(Message_Box_Add) With_Args("Error on Word")
Use Builtin(Message_Box_Add) With_Args(#Com_err_info.ErrorWord)
 
Use Builtin(Message_Box_Show)
 
Endroutine
 
Evtroutine Handling(#Bookmarks.ComponentError)
 
Use Builtin(Message_Box_Add) With_Args("Error on Bookmarks")
Use Builtin(Message_Box_Add) With_Args(#Com_err_info.ErrorWord)
 
Use Builtin(Message_Box_Show)
 
Endroutine
 
Evtroutine Handling(#Com_Owner.Closing)

* Drop all references and ensure Word quits correctly
#Word.Documents.Close
 
If (#Word *IsNot *null)
 
#Word.Quit
 
Endif
 
Endroutine
 
End_Com

背景に関する注意事項

LANSAの実行時エラーを処理するには、LANSAによって生成されたエラーと、ActiveXコントロールによって生成されたエラーの違いを理解する必要があります。

...