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

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