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

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