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

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