Tech Articles


How to capture error messages from an ActiveX control


Normally when you use OLEObject to connect to an ActiveX control and encounter an error, you will get the generic run time error ‘R0035 – Application terminated. Error calling external object function xxx’.

 

I have run across a very simple way to capture the actual error code and message generated by the ActiveX control.

 

First, create a new Standard Class object and select oleobject for the type.

 

Next add the following instance variables:

 

ULong ErrorCode

String ErrorText

 

Then add this code to the externalexception event:

 

ErrorCode = ResultCode

ErrorText = Description

 

Finally save the object as n_oleobject.

 

In your script that calls the ActiveX control functions you will do the following:

 

n_OLEObject oleTheObj

Integer li_rc

 

oleTheObj = Create n_OLEObject

li_rc = oleTheObj.ConnectToNewObject(“TheObject.Name”)

If li_rc = 0 Then

   try

      oleTheObj.TheFunction()

   catch ( RuntimeError rte )

      PopulateError(oleTheObj.ErrorCode, oleTheObj.ErrorText)

      MessageBox(“OLE Runtime Error #” + &

            String(Error.Number), Error.Text, StopSign!)

      oleTheObj.DisconnectObject()

      Return

   end try

   oleTheObj.DisconnectObject()

Else

   MessageBox(“OLE Connect Error #” + String(li_rc), &

         “Connect To Object Failed!”, StopSign!)

End If

 

You’ll notice that in the catch section I used PopulateError to get the instance variables with the error information. I did this so I would also have the objectname/scriptname/linenumber for error logging if this were a real application.

Comments (0)
There are no comments posted here yet

Find Articles by Tag

Validation Resize C# Debugger COM Data DataType License Sort JSON Linux OS Text Configuration Syntax Web API Transaction TLS/SSL Android Open Source DataWindow SOAP Icon OrcaScript Script Class 64-bit CI/CD Web Service Proxy RESTClient Filter WebBrowser ActiveX Oracle Export JSON RibbonBar Window Git Database Table Array .NET Std Framework RichTextEdit Control Messagging OAuth 2.0 PBNI Azure Model Outlook PowerServer Web WinAPI .NET DataStore Elevate Conference CrypterObject NativePDF Windows 10 Icons HTTPClient Database Profile Database Table Schema REST Error PowerScript (PS) SnapDevelop OAuth PowerBuilder Compiler Performance SqlExecutor PowerServer Mobile Trial SnapObjects Authentication SDK TreeView Database Object Encoding Branch & Merge iOS Database Table Data Jenkins MessageBox SVN Interface Menu DLL RibbonBar Builder Application Expression DragDrop Graph DevOps Encryption Import Migration ODBC SQL PBDOM Variable Debug Event UI Modernization PostgreSQL ODBC driver Mobile Service Database Connection Deployment 32-bit Source Code Repository PDF JSONGenerator TFS UI Themes Bug External Functions DataWindow JSON API PBVM PowerBuilder GhostScript IDE Database Painter Stored Procedure Export Event Handler Authorization UI Charts Installation Testing Source Control Import JSON Debugging CoderObject SQL Server PowerBuilder (Appeon) Design OLE Windows OS Visual Studio SqlModelMapper XML File PostgreSQL Excel TortoiseGit InfoMaker BLOB Platform PFC JSONParser Database Automated Testing .NET Assembly PDFlib Event Handling